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
TreeMap
so 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
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 Summary
Constructors Constructor Description QueryContext(Map<String,Object> context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowReturnPartialResults(boolean defaultValue)
Map<String,Object>
asMap()
boolean
containsKey(String key)
Check if the given key is set.static QueryContext
empty()
boolean
equals(Object o)
Object
get(String key)
Return a value as a genericObject
, returningnull
if the context value is not set.Boolean
getBoolean(String key)
Return a value as anBoolean
, returning {@link null} if the context value is not set.boolean
getBoolean(String key, boolean defaultValue)
Return a value as anboolean
, returning the default value if the context value is not set.String
getBrokerServiceName()
long
getDefaultTimeout()
boolean
getEnableJoinFilterPushDown()
boolean
getEnableJoinFilterRewrite()
boolean
getEnableJoinFilterRewriteValueColumnFilters()
boolean
getEnableJoinLeftScanDirect()
boolean
getEnableParallelMerges()
boolean
getEnableRewriteJoinToFilter()
<E extends Enum<E>>
EgetEnum(String key, Class<E> clazz, E defaultValue)
Float
getFloat(String key)
Return a value as anFloat
, returning {@link null} if the context value is not set.float
getFloat(String key, float defaultValue)
Return a value as anfloat
, returning the default value if the context value is not set.Granularity
getGranularity(String key, com.fasterxml.jackson.databind.ObjectMapper jsonMapper)
HumanReadableBytes
getHumanReadableBytes(String key, HumanReadableBytes defaultValue)
int
getInSubQueryThreshold()
int
getInSubQueryThreshold(int defaultValue)
Integer
getInt(String key)
Return a value as anInteger
, returning {@link null} if the context value is not set.int
getInt(String key, int defaultValue)
Return a value as anint
, returning the default value if the context value is not set.long
getJoinFilterRewriteMaxSize()
String
getLane()
Long
getLong(String key)
Return a value as anLong
, returning {@link null} if the context value is not set.long
getLong(String key, long defaultValue)
Return a value as anlong
, returning the default value if the context value is not set.long
getMaxQueuedBytes(long defaultValue)
long
getMaxScatterGatherBytes()
String
getMaxSubqueryMemoryBytes(String defaultMemoryBytes)
int
getMaxSubqueryRows(int defaultSize)
int
getNumRetriesOnMissingSegments(int defaultValue)
int
getParallelMergeInitialYieldRows(int defaultValue)
int
getParallelMergeParallelism(int defaultValue)
int
getParallelMergeSmallBatchRows(int defaultValue)
int
getPriority()
int
getPriority(int defaultValue)
String
getString(String key)
Return a value as anString
, returning {@link null} if the context value is not set.String
getString(String key, String defaultValue)
long
getTimeout()
long
getTimeout(long defaultTimeout)
int
getUncoveredIntervalsLimit()
int
getUncoveredIntervalsLimit(int defaultValue)
QueryContexts.Vectorize
getVectorize()
QueryContexts.Vectorize
getVectorize(QueryContexts.Vectorize defaultValue)
QueryContexts.Vectorize
getVectorizeVirtualColumns()
QueryContexts.Vectorize
getVectorizeVirtualColumns(QueryContexts.Vectorize defaultValue)
int
getVectorSize()
int
getVectorSize(int defaultSize)
int
hashCode()
boolean
hasTimeout()
boolean
isBySegment()
boolean
isBySegment(boolean defaultValue)
boolean
isDebug()
boolean
isEmpty()
boolean
isFinalize(boolean defaultValue)
boolean
isPopulateCache()
boolean
isPopulateCache(boolean defaultValue)
boolean
isPopulateResultLevelCache()
boolean
isPopulateResultLevelCache(boolean defaultValue)
boolean
isSecondaryPartitionPruningEnabled()
boolean
isSerializeDateTimeAsLong(boolean defaultValue)
boolean
isSerializeDateTimeAsLongInner(boolean defaultValue)
boolean
isTimeBoundaryPlanningEnabled()
boolean
isUseCache()
boolean
isUseCache(boolean defaultValue)
boolean
isUseNestedForUnknownTypeInSubquery(boolean defaultUseNestedForUnkownTypeInSubquery)
boolean
isUseResultLevelCache()
boolean
isUseResultLevelCache(boolean defaultValue)
static QueryContext
of(Map<String,Object> context)
String
toString()
void
verifyMaxQueryTimeout(long maxQueryTimeout)
void
verifyMaxScatterGatherBytes(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 returnnull
if the value is not set.
-
get
@Nullable public Object get(String key)
Return a value as a genericObject
, returningnull
if 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)
-
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)
-
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)
-
isTimeBoundaryPlanningEnabled
public boolean isTimeBoundaryPlanningEnabled()
-
getBrokerServiceName
public String getBrokerServiceName()
-
-