Class QueryContext

java.lang.Object
org.apache.druid.query.QueryContext

public class QueryContext extends Object
Immutable holder for query context parameters with typed access methods. Code builds up a map of context values from serialization or during planning. Once that map is handed to the QueryContext, that map is effectively immutable.

The implementation uses a TreeMap so that the serialized form of a query lists context values in a deterministic order. Jackson will call getContext() on the query, which will call asMap() here, which returns the sorted TreeMap.

The TreeMap is a mutable class. We'd prefer an immutable class, but we can choose either ordering or immutability. Since the semantics of the context is that it is immutable once it is placed in a query. Code should NEVER get the context map from a query and modify it, even if the actual implementation allows it.

  • Constructor Details

  • Method Details

    • empty

      public static QueryContext empty()
    • of

      public static QueryContext of(Map<String,Object> context)
    • isEmpty

      public boolean isEmpty()
    • asMap

      public Map<String,Object> asMap()
    • containsKey

      public boolean containsKey(String key)
      Check if the given key is set. If the client will then fetch the value, consider using one of the get<Type>(String key) methods instead: they each return null if the value is not set.
    • get

      @Nullable public Object get(String key)
      Return a value as a generic Object, returning null if the context value is not set.
    • getString

      @Nullable public String getString(String key)
      Return a value as an String, returning
      invalid @link
      {@link null
      } if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getString

      public String getString(String key, String defaultValue)
    • getBoolean

      public Boolean getBoolean(String key)
      Return a value as an Boolean, returning
      invalid @link
      {@link null
      } if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Return a value as an boolean, returning the default value if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getInt

      public Integer getInt(String key)
      Return a value as an Integer, returning
      invalid @link
      {@link null
      } if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getInt

      public int getInt(String key, int defaultValue)
      Return a value as an int, returning the default value if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getLong

      public Long getLong(String key)
      Return a value as an Long, returning
      invalid @link
      {@link null
      } if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getLong

      public long getLong(String key, long defaultValue)
      Return a value as an long, returning the default value if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getFloat

      public Float getFloat(String key)
      Return a value as an Float, returning
      invalid @link
      {@link null
      } if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getFloat

      public float getFloat(String key, float defaultValue)
      Return a value as an float, returning the default value if the context value is not set.
      Throws:
      BadQueryContextException - for an invalid value
    • getHumanReadableBytes

      public HumanReadableBytes getHumanReadableBytes(String key, HumanReadableBytes defaultValue)
    • getHumanReadableBytes

      public HumanReadableBytes getHumanReadableBytes(String key, long defaultBytes)
    • getEnum

      public <E extends Enum<E>> E getEnum(String key, Class<E> clazz, E defaultValue)
    • getGranularity

      public Granularity getGranularity(String key, com.fasterxml.jackson.databind.ObjectMapper jsonMapper)
    • isDebug

      public boolean isDebug()
    • isBySegment

      public boolean isBySegment()
    • isBySegment

      public boolean isBySegment(boolean defaultValue)
    • isPopulateCache

      public boolean isPopulateCache()
    • isPopulateCache

      public boolean isPopulateCache(boolean defaultValue)
    • isUseCache

      public boolean isUseCache()
    • isUseCache

      public boolean isUseCache(boolean defaultValue)
    • isPopulateResultLevelCache

      public boolean isPopulateResultLevelCache()
    • isPopulateResultLevelCache

      public boolean isPopulateResultLevelCache(boolean defaultValue)
    • isUseResultLevelCache

      public boolean isUseResultLevelCache()
    • isUseResultLevelCache

      public boolean isUseResultLevelCache(boolean defaultValue)
    • isFinalize

      public boolean isFinalize(boolean defaultValue)
    • isSerializeDateTimeAsLong

      public boolean isSerializeDateTimeAsLong(boolean defaultValue)
    • isSerializeDateTimeAsLongInner

      public boolean isSerializeDateTimeAsLongInner(boolean defaultValue)
    • getVectorize

      public QueryContexts.Vectorize getVectorize()
    • getVectorize

      public QueryContexts.Vectorize getVectorize(QueryContexts.Vectorize defaultValue)
    • getVectorizeVirtualColumns

      public QueryContexts.Vectorize getVectorizeVirtualColumns()
    • getVectorizeVirtualColumns

      public QueryContexts.Vectorize getVectorizeVirtualColumns(QueryContexts.Vectorize defaultValue)
    • getVectorSize

      public int getVectorSize()
    • getVectorSize

      public int getVectorSize(int defaultSize)
    • getMaxSubqueryRows

      public int getMaxSubqueryRows(int defaultSize)
    • getMaxSubqueryMemoryBytes

      public String getMaxSubqueryMemoryBytes(String defaultMemoryBytes)
    • isUseNestedForUnknownTypeInSubquery

      public boolean isUseNestedForUnknownTypeInSubquery(boolean defaultUseNestedForUnkownTypeInSubquery)
    • isUseNestedForUnknownTypeInSubquery

      public boolean isUseNestedForUnknownTypeInSubquery()
    • getUncoveredIntervalsLimit

      public int getUncoveredIntervalsLimit()
    • getUncoveredIntervalsLimit

      public int getUncoveredIntervalsLimit(int defaultValue)
    • getPriority

      public int getPriority()
    • getPriority

      public int getPriority(int defaultValue)
    • getLane

      public String getLane()
    • getEnableParallelMerges

      public boolean getEnableParallelMerges()
    • getParallelMergeInitialYieldRows

      public int getParallelMergeInitialYieldRows(int defaultValue)
    • getParallelMergeSmallBatchRows

      public int getParallelMergeSmallBatchRows(int defaultValue)
    • getParallelMergeParallelism

      public int getParallelMergeParallelism(int defaultValue)
    • getJoinFilterRewriteMaxSize

      public long getJoinFilterRewriteMaxSize()
    • getEnableJoinFilterPushDown

      public boolean getEnableJoinFilterPushDown()
    • getEnableJoinFilterRewrite

      public boolean getEnableJoinFilterRewrite()
    • isSecondaryPartitionPruningEnabled

      public boolean isSecondaryPartitionPruningEnabled()
    • getMaxQueuedBytes

      public long getMaxQueuedBytes(long defaultValue)
    • getMaxScatterGatherBytes

      public long getMaxScatterGatherBytes()
    • getEngine

      public String getEngine()
    • hasTimeout

      public boolean hasTimeout()
    • getTimeout

      public long getTimeout()
    • getTimeout

      public long getTimeout(long defaultTimeout)
    • getTimeoutDuration

      @Nullable public Duration getTimeoutDuration()
    • getDefaultTimeout

      public long getDefaultTimeout()
    • verifyMaxQueryTimeout

      public void verifyMaxQueryTimeout(long maxQueryTimeout)
    • getPerSegmentTimeout

      public long getPerSegmentTimeout()
    • getPerSegmentTimeout

      public long getPerSegmentTimeout(long defaultPerSegmentTimeout)
    • usePerSegmentTimeout

      public boolean usePerSegmentTimeout()
    • verifyMaxScatterGatherBytes

      public void verifyMaxScatterGatherBytes(long maxScatterGatherBytesLimit)
    • getNumRetriesOnMissingSegments

      public int getNumRetriesOnMissingSegments(int defaultValue)
    • allowReturnPartialResults

      public boolean allowReturnPartialResults(boolean defaultValue)
    • getEnableJoinFilterRewriteValueColumnFilters

      public boolean getEnableJoinFilterRewriteValueColumnFilters()
    • getCloneQueryMode

      public CloneQueryMode getCloneQueryMode()
    • getEnableRewriteJoinToFilter

      public boolean getEnableRewriteJoinToFilter()
    • getEnableJoinLeftScanDirect

      public boolean getEnableJoinLeftScanDirect()
    • getInSubQueryThreshold

      public int getInSubQueryThreshold()
    • getInSubQueryThreshold

      public int getInSubQueryThreshold(int defaultValue)
    • getInFunctionThreshold

      public int getInFunctionThreshold()
      At or above this threshold number of values, when planning SQL queries, use the SQL SCALAR_IN_ARRAY operator rather than a stack of SQL ORs. This speeds up planning for large sets of points because it is opaque to various expensive optimizations. But, because this does bypass certain optimizations, we only do the transformation above a certain threshold. The SCALAR_IN_ARRAY operator is still able to convert to InDimFilter or TypedInFilter.
    • getInFunctionExprThreshold

      public int getInFunctionExprThreshold()
      At or above this threshold, when converting the SEARCH operator to a native expression, use the "scalar_in_array" function rather than a sequence of equals (==) separated by or (||). This is typically a lower threshold than getInFunctionThreshold(), because it does not prevent any SQL planning optimizations, and it speeds up query execution.
    • isTimeBoundaryPlanningEnabled

      public boolean isTimeBoundaryPlanningEnabled()
    • isCatalogValidationEnabled

      public boolean isCatalogValidationEnabled()
    • isExtendedFilteredSumRewrite

      public boolean isExtendedFilteredSumRewrite()
    • getFullReport

      public boolean getFullReport()
      Returns true if QueryContexts.CTX_FULL_REPORT is set to true, false if it is set to false or not set.
    • getQueryResourceId

      public QueryResourceId getQueryResourceId()
    • getBrokerServiceName

      public String getBrokerServiceName()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isDecoupledMode

      public boolean isDecoupledMode()
    • override

      public QueryContext override(Map<String,Object> contextOverride)
    • override

      public QueryContext override(QueryContext queryContext)
    • isPrePlanned

      public boolean isPrePlanned()
    • isRealtimeSegmentsOnly

      public boolean isRealtimeSegmentsOnly()