Package org.apache.druid.query.groupby
Class GroupByQuery
- java.lang.Object
-
- org.apache.druid.query.BaseQuery<ResultRow>
-
- org.apache.druid.query.groupby.GroupByQuery
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGroupByQuery.Builder
-
Field Summary
Fields Modifier and Type Field Description static StringCTX_KEY_SORT_BY_DIMS_FIRSTstatic StringCTX_TIMESTAMP_RESULT_FIELDstatic StringCTX_TIMESTAMP_RESULT_FIELD_GRANULARITYstatic StringCTX_TIMESTAMP_RESULT_FIELD_INDEX-
Fields inherited from class org.apache.druid.query.BaseQuery
QUERY_ID, SQL_QUERY_ID, SUB_QUERY_ID
-
Fields inherited from interface org.apache.druid.query.Query
DATASOURCE_METADATA, GROUP_BY, SCAN, SEARCH, SEGMENT_METADATA, SELECT, TIME_BOUNDARY, TIMESERIES, TOPN, WINDOW_OPERATOR
-
-
Constructor Summary
Constructors Constructor Description GroupByQuery(DataSource dataSource, QuerySegmentSpec querySegmentSpec, VirtualColumns virtualColumns, DimFilter dimFilter, Granularity granularity, List<DimensionSpec> dimensions, List<AggregatorFactory> aggregatorSpecs, List<PostAggregator> postAggregatorSpecs, HavingSpec havingSpec, LimitSpec limitSpec, List<List<String>> subtotalsSpec, Map<String,Object> context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GroupByQuery.Builderbuilder()booleanequals(Object o)List<AggregatorFactory>getAggregatorSpecs()booleangetApplyLimitPushDownFromContext()booleangetContextSortByDimsFirst()List<DimensionSpec>getDimensions()DimFiltergetDimFilter()DimFiltergetFilter()HavingSpecgetHavingSpec()LimitSpecgetLimitSpec()List<PostAggregator>getPostAggregatorSpecs()Set<String>getRequiredColumns()Returns the set of columns that this query will need to access out of its datasource.com.google.common.collect.OrderinggetResultOrdering()Default implementation ofQuery.getResultOrdering()that usesOrdering.natural().intgetResultRowAggregatorStart()Returns the position of the first aggregator in ResultRows for this query.intgetResultRowDimensionStart()Returns the position of the first dimension in ResultRows for this query.booleangetResultRowHasTimestamp()Returns true if ResultRows for this query include timestamps, false otherwise.intgetResultRowPostAggregatorStart()Returns the position of the first post-aggregator in ResultRows for this query.RowSignaturegetResultRowSignature()Equivalent togetResultRowSignature(Finalization.UNKNOWN).RowSignaturegetResultRowSignature(RowSignature.Finalization finalization)Returns a result row signature, of the same size asgetResultRowSizeWithPostAggregators(), in the order that they will appear in ResultRows for this query.intgetResultRowSizeWithoutPostAggregators()Returns the size of ResultRows for this query when they do not include post-aggregators.intgetResultRowSizeWithPostAggregators()Returns the size of ResultRows for this query when they include post-aggregators.com.google.common.collect.Ordering<ResultRow>getRowOrdering(boolean granular)List<List<String>>getSubtotalsSpec()Subtotals spec may be empty which has a distinct meaning fromnull.StringgetType()org.joda.time.DateTimegetUniversalTimestamp()If this query has a single universal timestamp, return it.VirtualColumnsgetVirtualColumns()booleanhasFilters()inthashCode()booleanisApplyLimitPushDown()Sequence<ResultRow>postProcess(Sequence<ResultRow> results)Apply the havingSpec and limitSpec.StringtoString()GroupByQuerywithAggregatorSpecs(List<AggregatorFactory> aggregatorSpecs)Query<ResultRow>withDataSource(DataSource dataSource)GroupByQuerywithDimensionSpecs(List<DimensionSpec> dimensionSpecs)GroupByQuerywithDimFilter(DimFilter dimFilter)GroupByQuerywithLimitSpec(LimitSpec limitSpec)GroupByQuerywithOverriddenContext(Map<String,Object> contextOverride)GroupByQuerywithPostAggregatorSpecs(List<PostAggregator> postAggregatorSpecs)GroupByQuerywithQuerySegmentSpec(QuerySegmentSpec spec)Returns a new query, identical to this one, but with a different associatedQuerySegmentSpec.GroupByQuerywithSubtotalsSpec(List<List<String>> subtotalsSpec)GroupByQuerywithVirtualColumns(VirtualColumns virtualColumns)-
Methods inherited from class org.apache.druid.query.BaseQuery
checkInterrupted, computeOverriddenContext, computeOverridenContext, context, getContext, getDataSource, getDuration, getGranularity, getId, getIntervals, getQuerySegmentSpec, getQuerySegmentSpecForLookUp, getRunner, getSubQueryId, getTimezone, isDescending, withId, withSqlQueryId, withSubQueryId
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.druid.query.Query
getContextBoolean, getContextHumanReadableBytes, getContextValue, getMostSpecificId, getSqlQueryId, optimizeForSegment, withDefaultSubQueryId, withLane, withPriority
-
-
-
-
Field Detail
-
CTX_KEY_SORT_BY_DIMS_FIRST
public static final String CTX_KEY_SORT_BY_DIMS_FIRST
- See Also:
- Constant Field Values
-
CTX_TIMESTAMP_RESULT_FIELD
public static final String CTX_TIMESTAMP_RESULT_FIELD
- See Also:
- Constant Field Values
-
CTX_TIMESTAMP_RESULT_FIELD_GRANULARITY
public static final String CTX_TIMESTAMP_RESULT_FIELD_GRANULARITY
- See Also:
- Constant Field Values
-
CTX_TIMESTAMP_RESULT_FIELD_INDEX
public static final String CTX_TIMESTAMP_RESULT_FIELD_INDEX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GroupByQuery
public GroupByQuery(DataSource dataSource, QuerySegmentSpec querySegmentSpec, VirtualColumns virtualColumns, @Nullable DimFilter dimFilter, Granularity granularity, List<DimensionSpec> dimensions, List<AggregatorFactory> aggregatorSpecs, List<PostAggregator> postAggregatorSpecs, @Nullable HavingSpec havingSpec, @Nullable LimitSpec limitSpec, @Nullable List<List<String>> subtotalsSpec, Map<String,Object> context)
-
-
Method Detail
-
builder
public static GroupByQuery.Builder builder()
-
getVirtualColumns
public VirtualColumns getVirtualColumns()
-
getDimensions
public List<DimensionSpec> getDimensions()
-
getAggregatorSpecs
public List<AggregatorFactory> getAggregatorSpecs()
-
getPostAggregatorSpecs
public List<PostAggregator> getPostAggregatorSpecs()
-
getHavingSpec
public HavingSpec getHavingSpec()
-
getLimitSpec
public LimitSpec getLimitSpec()
-
getSubtotalsSpec
@Nullable public List<List<String>> getSubtotalsSpec()
Subtotals spec may be empty which has a distinct meaning fromnull.
-
getResultRowSignature
public RowSignature getResultRowSignature()
Equivalent togetResultRowSignature(Finalization.UNKNOWN).
-
getResultRowSignature
public RowSignature getResultRowSignature(RowSignature.Finalization finalization)
Returns a result row signature, of the same size asgetResultRowSizeWithPostAggregators(), in the order that they will appear in ResultRows for this query. Aggregator types in the signature depend on the value offinalization. If finalization isRowSignature.Finalization.UNKNOWN, this method returns a cached object.
-
getResultRowSizeWithoutPostAggregators
public int getResultRowSizeWithoutPostAggregators()
Returns the size of ResultRows for this query when they do not include post-aggregators.
-
getResultRowSizeWithPostAggregators
public int getResultRowSizeWithPostAggregators()
Returns the size of ResultRows for this query when they include post-aggregators.
-
getUniversalTimestamp
@Nullable public org.joda.time.DateTime getUniversalTimestamp()
If this query has a single universal timestamp, return it. Otherwise return null. IfBaseQuery.getIntervals()is empty, there are no results (or timestamps) so this method returns null. This method will return a nonnull timestamp in the following two cases: 1) CTX_KEY_FUDGE_TIMESTAMP is set (in which case this timestamp will be returned). 2) Granularity is "ALL". If this method returns null, thengetResultRowHasTimestamp()will return true. The reverse is also true: if this method returns nonnull, thengetResultRowHasTimestamp()will return false.
-
getResultRowHasTimestamp
public boolean getResultRowHasTimestamp()
Returns true if ResultRows for this query include timestamps, false otherwise.
-
getResultRowDimensionStart
public int getResultRowDimensionStart()
Returns the position of the first dimension in ResultRows for this query.
-
getResultRowAggregatorStart
public int getResultRowAggregatorStart()
Returns the position of the first aggregator in ResultRows for this query.
-
getResultRowPostAggregatorStart
public int getResultRowPostAggregatorStart()
Returns the position of the first post-aggregator in ResultRows for this query.
-
hasFilters
public boolean hasFilters()
-
getType
public String getType()
-
getContextSortByDimsFirst
public boolean getContextSortByDimsFirst()
-
isApplyLimitPushDown
public boolean isApplyLimitPushDown()
-
getApplyLimitPushDownFromContext
public boolean getApplyLimitPushDownFromContext()
-
getResultOrdering
public com.google.common.collect.Ordering getResultOrdering()
Description copied from class:BaseQueryDefault implementation ofQuery.getResultOrdering()that usesOrdering.natural(). If your query result type T is not Comparable, you must override this method.- Specified by:
getResultOrderingin interfaceQuery<ResultRow>- Overrides:
getResultOrderingin classBaseQuery<ResultRow>
-
getRowOrdering
public com.google.common.collect.Ordering<ResultRow> getRowOrdering(boolean granular)
-
postProcess
public Sequence<ResultRow> postProcess(Sequence<ResultRow> results)
Apply the havingSpec and limitSpec. Because havingSpecs are not thread safe, and because they are applied during accumulation of the returned sequence, callers must take care to avoid accumulating two different Sequences returned by this method in two different threads.- Parameters:
results- sequence of rows to apply havingSpec and limitSpec to- Returns:
- sequence of rows after applying havingSpec and limitSpec
-
getRequiredColumns
@Nullable public Set<String> getRequiredColumns()
Description copied from interface:QueryReturns 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.
-
withOverriddenContext
public GroupByQuery withOverriddenContext(Map<String,Object> contextOverride)
-
withQuerySegmentSpec
public GroupByQuery withQuerySegmentSpec(QuerySegmentSpec spec)
Description copied from interface:QueryReturns a new query, identical to this one, but with a different associatedQuerySegmentSpec. This often changes the behavior ofQuery.getRunner(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).
-
withVirtualColumns
public GroupByQuery withVirtualColumns(VirtualColumns virtualColumns)
-
withDimFilter
public GroupByQuery withDimFilter(@Nullable DimFilter dimFilter)
-
withDataSource
public Query<ResultRow> withDataSource(DataSource dataSource)
-
withDimensionSpecs
public GroupByQuery withDimensionSpecs(List<DimensionSpec> dimensionSpecs)
-
withLimitSpec
public GroupByQuery withLimitSpec(LimitSpec limitSpec)
-
withAggregatorSpecs
public GroupByQuery withAggregatorSpecs(List<AggregatorFactory> aggregatorSpecs)
-
withSubtotalsSpec
public GroupByQuery withSubtotalsSpec(@Nullable List<List<String>> subtotalsSpec)
-
withPostAggregatorSpecs
public GroupByQuery withPostAggregatorSpecs(List<PostAggregator> postAggregatorSpecs)
-
-