Class GroupByQuery
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringContext key for whether this query has any "dropped" dimensions.static final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.apache.druid.query.BaseQuery
QUERY_ID, SQL_QUERY_ID, SUB_QUERY_IDFields inherited from interface org.apache.druid.query.Query
DATASOURCE_METADATA, GROUP_BY, SCAN, SEARCH, SEGMENT_METADATA, SELECT, TIME_BOUNDARY, TIMESERIES, TOPN, UNION_QUERY, WINDOW_OPERATOR -
Constructor Summary
ConstructorsConstructorDescriptionGroupByQuery(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
Modifier and TypeMethodDescriptionstatic GroupByQuery.Builderbuilder()booleanbooleanbooleangetOrderingAndDimensions(boolean granular) Returns the set of columns that this query will need to access out of its datasource.com.google.common.collect.OrderingDefault implementation ofQuery.getResultOrdering()that usesOrdering.natural().intReturns the position of the first aggregator in ResultRows for this query.intReturns the position of the first dimension in ResultRows for this query.booleanReturns true if ResultRows for this query include timestamps, false otherwise.intReturns the position of the first post-aggregator in ResultRows for this query.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.intReturns the size of ResultRows for this query when they do not include post-aggregators.intReturns the size of ResultRows for this query when they include post-aggregators.com.google.common.collect.Ordering<ResultRow>getRowOrdering(boolean granular) Subtotals spec may be empty which has a distinct meaning fromnull.getType()org.joda.time.DateTimeIf this query has a single universal timestamp, return it.booleanbooleaninthashCode()booleanbooleanSignals that the execution of this query could also transparently handle the inputQueryDataSourceas well.postProcess(Sequence<ResultRow> results) Apply the havingSpec and limitSpec.toString()withAggregatorSpecs(List<AggregatorFactory> aggregatorSpecs) withDataSource(DataSource dataSource) withDimensionSpecs(List<DimensionSpec> dimensionSpecs) withDimFilter(DimFilter dimFilter) withLimitSpec(LimitSpec limitSpec) withOverriddenContext(Map<String, Object> contextOverride) withPostAggregatorSpecs(List<PostAggregator> postAggregatorSpecs) Returns a new query, identical to this one, but with a different associatedQuerySegmentSpec.withSubtotalsSpec(List<List<String>> subtotalsSpec) withVirtualColumns(VirtualColumns virtualColumns) Methods inherited from class org.apache.druid.query.BaseQuery
calculateDuration, checkInterrupted, computeOverriddenContext, computeOverridenContext, context, getContext, getDataSource, getDuration, getGranularity, getId, getIntervals, getQuerySegmentSpec, getRunner, getSubQueryId, getTimezone, withId, withSqlQueryId, withSubQueryIdMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.druid.query.Query
getContextBoolean, getContextHumanReadableBytes, getContextValue, getMostSpecificId, getSingleInterval, getSqlQueryId, optimizeForSegment, withDefaultSubQueryId, withLane, withPriority
-
Field Details
-
CTX_KEY_SORT_BY_DIMS_FIRST
- See Also:
-
CTX_TIMESTAMP_RESULT_FIELD
- See Also:
-
CTX_TIMESTAMP_RESULT_FIELD_GRANULARITY
- See Also:
-
CTX_TIMESTAMP_RESULT_FIELD_INDEX
- See Also:
-
CTX_HAS_DROPPED_DIMENSIONS
Context key for whether this query has any "dropped" dimensions. This is set true for queries like "GROUP BY 'constant'", and enablesGroupingEngine.summaryRowPreconditions(GroupByQuery)to correctly determine whether to include a summary row.- See Also:
-
-
Constructor Details
-
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 Details
-
builder
-
getVirtualColumns
-
getDimFilter
-
getDimensions
-
getAggregatorSpecs
-
getPostAggregatorSpecs
-
getHavingSpec
-
getLimitSpec
-
getSubtotalsSpec
Subtotals spec may be empty which has a distinct meaning fromnull. -
getResultRowSignature
-
getResultRowSignature
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() -
getFilter
-
getType
-
getContextSortByDimsFirst
public boolean getContextSortByDimsFirst() -
isApplyLimitPushDown
public boolean isApplyLimitPushDown() -
getApplyLimitPushDownFromContext
public boolean getApplyLimitPushDownFromContext() -
hasDroppedDimensions
public boolean hasDroppedDimensions() -
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
-
getDimensionNamesInOrder
-
getOrderingAndDimensions
-
postProcess
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
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 a
QueryDataSource, 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.
-
getGroupingColumns
-
withOverriddenContext
-
withQuerySegmentSpec
Description copied from interface:QueryReturns a new query, identical to this one, but with a different associatedQuerySegmentSpec.This often changes the behavior of
Query.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
-
withDimFilter
-
withDataSource
-
withDimensionSpecs
-
withLimitSpec
-
withAggregatorSpecs
-
withSubtotalsSpec
-
withPostAggregatorSpecs
-
toString
-
equals
-
hashCode
public int hashCode() -
mayCollapseQueryDataSource
public boolean mayCollapseQueryDataSource()Description copied from interface:QuerySignals that the execution of this query could also transparently handle the inputQueryDataSourceas well. This is a not-so-nice way to support thatGroupByQuerycould collapse otherGroupByQuery-ies inQueryDataSource-es.
-