Class GroupByQuery

java.lang.Object
org.apache.druid.query.BaseQuery<ResultRow>
org.apache.druid.query.groupby.GroupByQuery
All Implemented Interfaces:
Query<ResultRow>

public class GroupByQuery extends BaseQuery<ResultRow>
  • Field Details

  • Constructor Details

  • Method Details

    • builder

      public static GroupByQuery.Builder builder()
    • getVirtualColumns

      public VirtualColumns getVirtualColumns()
    • getDimFilter

      @Nullable public DimFilter getDimFilter()
    • 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 from null.
    • getResultRowSignature

      public RowSignature getResultRowSignature()
    • getResultRowSignature

      public RowSignature getResultRowSignature(RowSignature.Finalization finalization)
      Returns a result row signature, of the same size as getResultRowSizeWithPostAggregators(), in the order that they will appear in ResultRows for this query. Aggregator types in the signature depend on the value of finalization. If finalization is RowSignature.Finalization.UNKNOWN, this method returns a cached object.
      See Also:
    • 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. If BaseQuery.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, then getResultRowHasTimestamp() will return true. The reverse is also true: if this method returns nonnull, then getResultRowHasTimestamp() will return false.
    • getResultRowHasTimestamp

      public boolean getResultRowHasTimestamp()
      Returns true if ResultRows for this query include timestamps, false otherwise.
      See Also:
    • 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

      @Nullable public DimFilter getFilter()
    • getType

      public String 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: BaseQuery
      Default implementation of Query.getResultOrdering() that uses Ordering.natural(). If your query result type T is not Comparable, you must override this method.
      Specified by:
      getResultOrdering in interface Query<ResultRow>
      Overrides:
      getResultOrdering in class BaseQuery<ResultRow>
    • getRowOrdering

      public com.google.common.collect.Ordering<ResultRow> getRowOrdering(boolean granular)
    • getDimensionNamesInOrder

      public List<String> getDimensionNamesInOrder()
    • getOrderingAndDimensions

      public GroupByQuery.OrderingAndDimensions getOrderingAndDimensions(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: Query
      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 a QueryDataSource, this method will not return the columns used by that subquery. As another example, if a query is built on a JoinDataSource, 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

      public List<String> getGroupingColumns()
    • withOverriddenContext

      public GroupByQuery withOverriddenContext(Map<String,Object> contextOverride)
    • withQuerySegmentSpec

      public GroupByQuery withQuerySegmentSpec(QuerySegmentSpec spec)
      Description copied from interface: Query
      Returns a new query, identical to this one, but with a different associated QuerySegmentSpec.

      This often changes the behavior of Query.getRunner(QuerySegmentWalker), since most queries inherit that method from BaseQuery, which implements it by calling QuerySegmentSpec.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)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class BaseQuery<ResultRow>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class BaseQuery<ResultRow>
    • mayCollapseQueryDataSource

      public boolean mayCollapseQueryDataSource()
      Description copied from interface: Query
      Signals that the execution of this query could also transparently handle the input QueryDataSource as well. This is a not-so-nice way to support that GroupByQuery could collapse other GroupByQuery-ies in QueryDataSource-es.