Package org.apache.druid.query
Interface Query<T>
-
- All Known Implementing Classes:
BaseQuery
,DataSourceMetadataQuery
,GroupByQuery
,ScanQuery
,SearchQuery
,SegmentMetadataQuery
,SelectQuery
,TimeBoundaryQuery
,TimeseriesQuery
,TopNQuery
,WindowOperatorQuery
public interface Query<T>
-
-
Field Summary
Fields Modifier and Type Field Description static String
DATASOURCE_METADATA
static String
GROUP_BY
static String
SCAN
static String
SEARCH
static String
SEGMENT_METADATA
static String
SELECT
static String
TIME_BOUNDARY
static String
TIMESERIES
static String
TOPN
static String
WINDOW_OPERATOR
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default QueryContext
context()
Returns the query context as aQueryContext
, which provides convenience methods for accessing typed context values.Map<String,Object>
getContext()
Returns the context as an (immutable) map.default boolean
getContextBoolean(String key, boolean defaultValue)
Deprecated.usequeryContext().getBoolean()
instead.default HumanReadableBytes
getContextHumanReadableBytes(String key, HumanReadableBytes defaultValue)
Deprecated.usequeryContext().getContextHumanReadableBytes()
instead.default <ContextType>
ContextTypegetContextValue(String key)
Deprecated.usequeryContext().get<Type>()
insteadDataSource
getDataSource()
org.joda.time.Duration
getDuration()
DimFilter
getFilter()
Granularity
getGranularity()
String
getId()
List<org.joda.time.Interval>
getIntervals()
default String
getMostSpecificId()
Returns a most specific ID of this query; if it is a subquery, this will return its subquery ID.default Set<String>
getRequiredColumns()
Returns the set of columns that this query will need to access out of its datasource.com.google.common.collect.Ordering<T>
getResultOrdering()
Comparator that represents the order in which results are generated from theQueryRunnerFactory.createRunner(Segment)
andQueryRunnerFactory.mergeRunners(QueryProcessingPool, Iterable)
calls.QueryRunner<T>
getRunner(QuerySegmentWalker walker)
default String
getSqlQueryId()
String
getSubQueryId()
Returns the subQueryId of this query.org.joda.time.DateTimeZone
getTimezone()
String
getType()
default VirtualColumns
getVirtualColumns()
boolean
hasFilters()
boolean
isDescending()
default Query<T>
optimizeForSegment(PerSegmentQueryOptimizationContext optimizationContext)
Query<T>
withDataSource(DataSource dataSource)
default Query<T>
withDefaultSubQueryId()
Query<T>
withId(String id)
default Query<T>
withLane(String lane)
Query<T>
withOverriddenContext(Map<String,Object> contextOverride)
default Query<T>
withPriority(int priority)
Query<T>
withQuerySegmentSpec(QuerySegmentSpec spec)
Returns a new query, identical to this one, but with a different associatedQuerySegmentSpec
.default Query<T>
withSqlQueryId(String sqlQueryId)
Query<T>
withSubQueryId(String subQueryId)
Returns a copy of this query with a new subQueryId (seegetSubQueryId()
.
-
-
-
Field Detail
-
DATASOURCE_METADATA
static final String DATASOURCE_METADATA
- See Also:
- Constant Field Values
-
GROUP_BY
static final String GROUP_BY
- See Also:
- Constant Field Values
-
SCAN
static final String SCAN
- See Also:
- Constant Field Values
-
SEARCH
static final String SEARCH
- See Also:
- Constant Field Values
-
SEGMENT_METADATA
static final String SEGMENT_METADATA
- See Also:
- Constant Field Values
-
SELECT
static final String SELECT
- See Also:
- Constant Field Values
-
TIME_BOUNDARY
static final String TIME_BOUNDARY
- See Also:
- Constant Field Values
-
TIMESERIES
static final String TIMESERIES
- See Also:
- Constant Field Values
-
TOPN
static final String TOPN
- See Also:
- Constant Field Values
-
WINDOW_OPERATOR
static final String WINDOW_OPERATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDataSource
DataSource getDataSource()
-
hasFilters
boolean hasFilters()
-
getFilter
DimFilter getFilter()
-
getType
String getType()
-
getRunner
QueryRunner<T> getRunner(QuerySegmentWalker walker)
-
getIntervals
List<org.joda.time.Interval> getIntervals()
-
getDuration
org.joda.time.Duration getDuration()
-
getGranularity
Granularity getGranularity()
-
getTimezone
org.joda.time.DateTimeZone getTimezone()
-
context
default QueryContext context()
Returns the query context as aQueryContext
, which provides convenience methods for accessing typed context values. The returned instance is a view on top of the context provided bygetContext()
.The default implementation is for backward compatibility. Derived classes should store and return the
QueryContext
directly.
-
getContextValue
@Deprecated @Nullable default <ContextType> ContextType getContextValue(String key)
Deprecated.usequeryContext().get<Type>()
insteadGet context value and cast to ContextType in an unsafe way. For safe conversion, it's recommended to use following methods instead:QueryContext.getBoolean(String)
QueryContext.getString(String)
QueryContext.getInt(String)
QueryContext.getLong(String)
QueryContext.getFloat(String)
QueryContext.getEnum(String, Class, Enum)
QueryContext.getHumanReadableBytes(String, HumanReadableBytes)
-
getContextBoolean
@Deprecated default boolean getContextBoolean(String key, boolean defaultValue)
Deprecated.usequeryContext().getBoolean()
instead.
-
getContextHumanReadableBytes
@Deprecated default HumanReadableBytes getContextHumanReadableBytes(String key, HumanReadableBytes defaultValue)
Deprecated.usequeryContext().getContextHumanReadableBytes()
instead.ReturnsHumanReadableBytes
for a specified context key. If the context is null or the key doesn't exist a caller specified default value is returned. A default implementation is provided since Query is an extension point. Extensions can choose to rely on this default to retain compatibility with core Druid.- Parameters:
key
- The context key value being looked updefaultValue
- The default to return if the key value doesn't exist or the context is null.- Returns:
HumanReadableBytes
-
isDescending
boolean isDescending()
-
getResultOrdering
com.google.common.collect.Ordering<T> getResultOrdering()
Comparator that represents the order in which results are generated from theQueryRunnerFactory.createRunner(Segment)
andQueryRunnerFactory.mergeRunners(QueryProcessingPool, Iterable)
calls. This is used to combine streams of results from different sources; for example, it's used by historicals to combine streams from different segments, and it's used by the broker to combine streams from different historicals. Important note: sometimes, this ordering is used in a type-unsafe way to order @{code Result} objects. Because of this, implementations should fall back to Ordering.natural()
when they are given an object that is not of type T.
-
withQuerySegmentSpec
Query<T> withQuerySegmentSpec(QuerySegmentSpec spec)
Returns a new query, identical to this one, but with a different associatedQuerySegmentSpec
. This often changes the behavior ofgetRunner(QuerySegmentWalker)
, since most queries inherit that method fromBaseQuery
, which implements it by callingQuerySegmentSpec.lookup(org.apache.druid.query.Query<T>, org.apache.druid.query.QuerySegmentWalker)
.
-
withSubQueryId
Query<T> withSubQueryId(String subQueryId)
Returns a copy of this query with a new subQueryId (seegetSubQueryId()
.
-
getSubQueryId
@Nullable String getSubQueryId()
Returns the subQueryId of this query. This is set by ClientQuerySegmentWalker (the entry point for the Broker's query stack) on any subqueries that it issues. It is null for the main query.
-
getMostSpecificId
default String getMostSpecificId()
Returns a most specific ID of this query; if it is a subquery, this will return its subquery ID. If it is a regular query without subqueries, this will return its query ID. This method should be called after the relevant ID is assigned usingwithId(java.lang.String)
orwithSubQueryId(java.lang.String)
.
-
withDataSource
Query<T> withDataSource(DataSource dataSource)
-
optimizeForSegment
default Query<T> optimizeForSegment(PerSegmentQueryOptimizationContext optimizationContext)
-
getVirtualColumns
default VirtualColumns getVirtualColumns()
-
getRequiredColumns
@Nullable default Set<String> getRequiredColumns()
Returns the set of columns that this query will need to access out of its datasource. This method does not "look into" what the datasource itself is doing. For example, if a query is built on aQueryDataSource
, this method will not return the columns used by that subquery. As another example, if a query is built on aJoinDataSource
, this method will not return the columns from the underlying datasources that are used by the join condition, unless those columns are also used by this query in other ways. Returns null if the set of required columns cannot be known ahead of time.
-
-