Package org.apache.druid.query
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 theQueryContext, that map is effectively immutable.The implementation uses a
TreeMapso that the serialized form of a query lists context values in a deterministic order. Jackson will callgetContext()on the query, which will callasMap()here, which returns the sortedTreeMap.The
TreeMapis 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 Summary
Constructors Constructor Description QueryContext(Map<String,Object> context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowReturnPartialResults(boolean defaultValue)Map<String,Object>asMap()booleancontainsKey(String key)Check if the given key is set.static QueryContextempty()booleanequals(Object o)Objectget(String key)Return a value as a genericObject, returningnullif the context value is not set.BooleangetBoolean(String key)Return a value as anBoolean, returning {@link null} if the context value is not set.booleangetBoolean(String key, boolean defaultValue)Return a value as anboolean, returning the default value if the context value is not set.StringgetBrokerServiceName()longgetDefaultTimeout()booleangetEnableJoinFilterPushDown()booleangetEnableJoinFilterRewrite()booleangetEnableJoinFilterRewriteValueColumnFilters()booleangetEnableJoinLeftScanDirect()booleangetEnableParallelMerges()booleangetEnableRewriteJoinToFilter()<E extends Enum<E>>
EgetEnum(String key, Class<E> clazz, E defaultValue)FloatgetFloat(String key)Return a value as anFloat, returning {@link null} if the context value is not set.floatgetFloat(String key, float defaultValue)Return a value as anfloat, returning the default value if the context value is not set.GranularitygetGranularity(String key, com.fasterxml.jackson.databind.ObjectMapper jsonMapper)HumanReadableBytesgetHumanReadableBytes(String key, long defaultBytes)HumanReadableBytesgetHumanReadableBytes(String key, HumanReadableBytes defaultValue)intgetInFunctionExprThreshold()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 (||).intgetInFunctionThreshold()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.intgetInSubQueryThreshold()intgetInSubQueryThreshold(int defaultValue)IntegergetInt(String key)Return a value as anInteger, returning {@link null} if the context value is not set.intgetInt(String key, int defaultValue)Return a value as anint, returning the default value if the context value is not set.longgetJoinFilterRewriteMaxSize()StringgetLane()LonggetLong(String key)Return a value as anLong, returning {@link null} if the context value is not set.longgetLong(String key, long defaultValue)Return a value as anlong, returning the default value if the context value is not set.longgetMaxQueuedBytes(long defaultValue)longgetMaxScatterGatherBytes()StringgetMaxSubqueryMemoryBytes(String defaultMemoryBytes)intgetMaxSubqueryRows(int defaultSize)intgetNumRetriesOnMissingSegments(int defaultValue)intgetParallelMergeInitialYieldRows(int defaultValue)intgetParallelMergeParallelism(int defaultValue)intgetParallelMergeSmallBatchRows(int defaultValue)intgetPriority()intgetPriority(int defaultValue)QueryResourceIdgetQueryResourceId()StringgetString(String key)Return a value as anString, returning {@link null} if the context value is not set.StringgetString(String key, String defaultValue)longgetTimeout()longgetTimeout(long defaultTimeout)intgetUncoveredIntervalsLimit()intgetUncoveredIntervalsLimit(int defaultValue)QueryContexts.VectorizegetVectorize()QueryContexts.VectorizegetVectorize(QueryContexts.Vectorize defaultValue)QueryContexts.VectorizegetVectorizeVirtualColumns()QueryContexts.VectorizegetVectorizeVirtualColumns(QueryContexts.Vectorize defaultValue)intgetVectorSize()intgetVectorSize(int defaultSize)inthashCode()booleanhasTimeout()booleanisBySegment()booleanisBySegment(boolean defaultValue)booleanisCatalogValidationEnabled()booleanisDebug()booleanisDecoupledMode()booleanisEmpty()booleanisExtendedFilteredSumRewrite()booleanisFinalize(boolean defaultValue)booleanisPopulateCache()booleanisPopulateCache(boolean defaultValue)booleanisPopulateResultLevelCache()booleanisPopulateResultLevelCache(boolean defaultValue)booleanisSecondaryPartitionPruningEnabled()booleanisSerializeDateTimeAsLong(boolean defaultValue)booleanisSerializeDateTimeAsLongInner(boolean defaultValue)booleanisTimeBoundaryPlanningEnabled()booleanisUseCache()booleanisUseCache(boolean defaultValue)booleanisUseNestedForUnknownTypeInSubquery()booleanisUseNestedForUnknownTypeInSubquery(boolean defaultUseNestedForUnkownTypeInSubquery)booleanisUseResultLevelCache()booleanisUseResultLevelCache(boolean defaultValue)static QueryContextof(Map<String,Object> context)StringtoString()voidverifyMaxQueryTimeout(long maxQueryTimeout)voidverifyMaxScatterGatherBytes(long maxScatterGatherBytesLimit)
-
-
-
Method Detail
-
empty
public static QueryContext empty()
-
of
public static QueryContext of(Map<String,Object> context)
-
isEmpty
public boolean isEmpty()
-
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 theget<Type>(String key)methods instead: they each returnnullif the value is not set.
-
get
@Nullable public Object get(String key)
Return a value as a genericObject, returningnullif the context value is not set.
-
getString
@Nullable public String getString(String key)
Return a value as anString, returning {@link null} if the context value is not set.- Throws:
BadQueryContextException- for an invalid value
-
getBoolean
public Boolean getBoolean(String key)
Return a value as anBoolean, returning {@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 anboolean, 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 anInteger, returning {@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 anint, 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 anLong, returning {@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 anlong, 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 anFloat, returning {@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 anfloat, 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)
-
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)
-
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()
-
hasTimeout
public boolean hasTimeout()
-
getTimeout
public long getTimeout()
-
getTimeout
public long getTimeout(long defaultTimeout)
-
getDefaultTimeout
public long getDefaultTimeout()
-
verifyMaxQueryTimeout
public void verifyMaxQueryTimeout(long maxQueryTimeout)
-
verifyMaxScatterGatherBytes
public void verifyMaxScatterGatherBytes(long maxScatterGatherBytesLimit)
-
getNumRetriesOnMissingSegments
public int getNumRetriesOnMissingSegments(int defaultValue)
-
allowReturnPartialResults
public boolean allowReturnPartialResults(boolean defaultValue)
-
getEnableJoinFilterRewriteValueColumnFilters
public boolean getEnableJoinFilterRewriteValueColumnFilters()
-
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 toInDimFilterorTypedInFilter.
-
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 thangetInFunctionThreshold(), 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()
-
getQueryResourceId
public QueryResourceId getQueryResourceId()
-
getBrokerServiceName
public String getBrokerServiceName()
-
isDecoupledMode
public boolean isDecoupledMode()
-
-