public abstract class Aggregate extends SingleRel
It corresponds to the GROUP BY operator in a SQL query
statement, together with the aggregate functions in the SELECT
clause.
Rules:
| Modifier and Type | Class and Description |
|---|---|
static class |
Aggregate.AggCallBinding
Implementation of the
SqlOperatorBinding interface for an
aggregate call applied to a set of operands in the
context of a LogicalAggregate. |
static class |
Aggregate.Group
What kind of roll-up is it?
|
RelNode.Context| Modifier and Type | Field and Description |
|---|---|
protected List<AggregateCall> |
aggCalls |
protected ImmutableBitSet |
groupSet |
com.google.common.collect.ImmutableList<ImmutableBitSet> |
groupSets |
boolean |
indicator
Whether there are indicator fields.
|
static com.google.common.base.Predicate<Aggregate> |
IS_NOT_GRAND_TOTAL |
static com.google.common.base.Predicate<Aggregate> |
IS_SIMPLE |
static com.google.common.base.Predicate<Aggregate> |
NO_INDICATOR |
digest, id, rowType, traitSet| Modifier | Constructor and Description |
|---|---|
protected |
Aggregate(RelInput input)
Creates an Aggregate by parsing serialized output.
|
protected |
Aggregate(RelOptCluster cluster,
RelTraitSet traits,
RelNode child,
boolean indicator,
ImmutableBitSet groupSet,
List<ImmutableBitSet> groupSets,
List<AggregateCall> aggCalls)
Creates an Aggregate.
|
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
allContain(List<ImmutableBitSet> groupSets,
int groupKey) |
RelOptCost |
computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq)
Returns the cost of this plan (not including children).
|
boolean |
containsDistinctCall()
Returns whether any of the aggregates are DISTINCT.
|
RelNode |
copy(RelTraitSet traitSet,
List<RelNode> inputs)
Creates a copy of this relational expression, perhaps changing traits and
inputs.
|
abstract Aggregate |
copy(RelTraitSet traitSet,
RelNode input,
boolean indicator,
ImmutableBitSet groupSet,
List<ImmutableBitSet> groupSets,
List<AggregateCall> aggCalls)
Creates a copy of this aggregate.
|
protected RelDataType |
deriveRowType() |
static RelDataType |
deriveRowType(RelDataTypeFactory typeFactory,
RelDataType inputRowType,
boolean indicator,
ImmutableBitSet groupSet,
List<ImmutableBitSet> groupSets,
List<AggregateCall> aggCalls)
Computes the row type of an
Aggregate before it exists. |
double |
estimateRowCount(RelMetadataQuery mq)
Returns an estimate of the number of rows this relational expression will
return.
|
RelWriter |
explainTerms(RelWriter pw)
Describes the inputs and attributes of this relational expression.
|
List<AggregateCall> |
getAggCallList()
Returns a list of calls to aggregate functions.
|
int |
getGroupCount()
Returns the number of grouping fields.
|
ImmutableBitSet |
getGroupSet()
Returns a bit set of the grouping fields.
|
com.google.common.collect.ImmutableList<ImmutableBitSet> |
getGroupSets()
Returns the list of grouping sets computed by this Aggregate.
|
Aggregate.Group |
getGroupType()
Returns the type of roll-up.
|
int |
getIndicatorCount()
Returns the number of indicator fields.
|
List<Pair<AggregateCall,String>> |
getNamedAggCalls()
Returns a list of calls to aggregate functions together with their output
field names.
|
private boolean |
isPredicate(RelNode input,
int index) |
boolean |
isValid(Litmus litmus,
RelNode.Context context)
Returns whether this relational expression is valid.
|
private boolean |
typeMatchesInferred(AggregateCall aggCall,
Litmus litmus)
Returns whether the inferred type of an
AggregateCall matches the
type it was given when it was created. |
childrenAccept, getInput, getInputs, replaceInputaccept, accept, collectVariablesSet, collectVariablesUsed, computeDigest, computeSelfCost, explain, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getQuery, getRelTypeName, getRows, getRowType, getTable, getTraitSet, getVariablesSet, getVariablesStopped, isDistinct, isKey, isValid, metadata, onRegister, recomputeDigest, register, sole, toStringpublic static final com.google.common.base.Predicate<Aggregate> IS_SIMPLE
Bug.CALCITE_461_FIXEDpublic static final com.google.common.base.Predicate<Aggregate> NO_INDICATOR
public static final com.google.common.base.Predicate<Aggregate> IS_NOT_GRAND_TOTAL
public final boolean indicator
We strongly discourage the use indicator fields, because they cause the
output row type of GROUPING SETS queries to be different from regular GROUP
BY queries, and recommend that you set this field to false.
protected final List<AggregateCall> aggCalls
protected final ImmutableBitSet groupSet
public final com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets
protected Aggregate(RelOptCluster cluster, RelTraitSet traits, RelNode child, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
All members of groupSets must be sub-sets of groupSet.
For a simple GROUP BY, groupSets is a singleton list
containing groupSet.
If GROUP BY is not specified,
or equivalently if GROUP BY () is specified,
groupSet will be the empty set,
and groupSets will have one element, that empty set.
If CUBE, ROLLUP or GROUPING SETS are
specified, groupSets will have additional elements,
but they must each be a subset of groupSet,
and they must be sorted by inclusion:
(0, 1, 2), (1), (0, 2), (0), ().
cluster - Clustertraits - Traitschild - Childindicator - Whether row type should include indicator fields to
indicate which grouping set is active; true is deprecatedgroupSet - Bit set of grouping fieldsgroupSets - List of all grouping sets; null for just groupSetaggCalls - Collection of calls to aggregate functionsprotected Aggregate(RelInput input)
private boolean isPredicate(RelNode input, int index)
public final RelNode copy(RelTraitSet traitSet, List<RelNode> inputs)
RelNodeSub-classes with other important attributes are encouraged to create variants of this method with more parameters.
copy in interface RelNodecopy in class AbstractRelNodetraitSet - Trait setinputs - Inputspublic abstract Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
traitSet - Traitsinput - Inputindicator - Whether row type should include indicator fields to
indicate which grouping set is active; must be true if
aggregate is not simplegroupSet - Bit set of grouping fieldsgroupSets - List of all grouping sets; null for just groupSetaggCalls - Collection of calls to aggregate functionsAggregate if any parameter differs from the value of
this Aggregate, or just this if all the parameters are
the samecopy(org.apache.calcite.plan.RelTraitSet, java.util.List)public List<AggregateCall> getAggCallList()
public List<Pair<AggregateCall,String>> getNamedAggCalls()
public int getGroupCount()
NOTE: The getGroupSet() data structure allows for the
grouping fields to not be on the leading edge. New code should, if
possible, assume that grouping fields are in arbitrary positions in the
input relational expression.
public int getIndicatorCount()
This is the same as getGroupCount() if indicator is
true, zero if indicator is false.
The offset of the first aggregate call in the output record is always groupCount + indicatorCount.
public ImmutableBitSet getGroupSet()
public com.google.common.collect.ImmutableList<ImmutableBitSet> getGroupSets()
groupSetpublic RelWriter explainTerms(RelWriter pw)
AbstractRelNodesuper.explainTerms, then call the
RelWriterImpl.input(String, RelNode)
and
RelWriterImpl.item(String, Object)
methods for each input and attribute.explainTerms in class SingleRelpw - Plan writerpublic double estimateRowCount(RelMetadataQuery mq)
RelNodeNOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use
RelMetadataQuery.getRowCount(org.apache.calcite.rel.RelNode), which gives plugins a chance to
override the rel's default ideas about row count.
estimateRowCount in interface RelNodeestimateRowCount in class SingleRelmq - Metadata querypublic RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
RelNodeNOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use
RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode), which gives plugins a
chance to override the rel's default ideas about cost.
computeSelfCost in interface RelNodecomputeSelfCost in class AbstractRelNodeplanner - Planner for cost calculationmq - Metadata queryprotected RelDataType deriveRowType()
deriveRowType in class SingleRelpublic static RelDataType deriveRowType(RelDataTypeFactory typeFactory, RelDataType inputRowType, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
Aggregate before it exists.typeFactory - Type factoryinputRowType - Input row typeindicator - Whether row type should include indicator fields to
indicate which grouping set is active; must be true if
aggregate is not simplegroupSet - Bit set of grouping fieldsgroupSets - List of all grouping sets; null for just groupSetaggCalls - Collection of calls to aggregate functionsprivate static boolean allContain(List<ImmutableBitSet> groupSets, int groupKey)
public boolean isValid(Litmus litmus, RelNode.Context context)
RelNodeIf assertions are enabled, this method is typically called with
litmus = THROW, as follows:
assert rel.isValid(Litmus.THROW)
This signals that the method can throw an AssertionError if it
is not valid.
isValid in interface RelNodeisValid in class AbstractRelNodelitmus - What to do if invalidcontext - Context for validity checkingprivate boolean typeMatchesInferred(AggregateCall aggCall, Litmus litmus)
AggregateCall matches the
type it was given when it was created.aggCall - Aggregate calllitmus - What to do if an error is detected (types do not match)public boolean containsDistinctCall()
public Aggregate.Group getGroupType()
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.