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 java.util.List<AggregateCall> |
aggCalls |
protected ImmutableBitSet |
groupSet |
com.google.common.collect.ImmutableList<ImmutableBitSet> |
groupSets |
boolean |
indicator
Deprecated.
|
static com.google.common.base.Predicate<Aggregate> |
IS_NOT_GRAND_TOTAL
Deprecated.
|
static com.google.common.base.Predicate<Aggregate> |
IS_SIMPLE
Deprecated.
|
static com.google.common.base.Predicate<Aggregate> |
NO_INDICATOR
Deprecated.
|
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,
java.util.List<ImmutableBitSet> groupSets,
java.util.List<AggregateCall> aggCalls)
Deprecated.
|
protected |
Aggregate(RelOptCluster cluster,
RelTraitSet traitSet,
RelNode input,
ImmutableBitSet groupSet,
java.util.List<ImmutableBitSet> groupSets,
java.util.List<AggregateCall> aggCalls)
Creates an Aggregate.
|
Modifier and Type | Method and Description |
---|---|
private static boolean |
allContain(java.util.List<ImmutableBitSet> groupSets,
int groupKey) |
static void |
checkIndicator(boolean indicator)
Used internally; will removed when
indicator is removed,
before 2.0. |
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,
java.util.List<RelNode> inputs)
Creates a copy of this relational expression, perhaps changing traits and
inputs.
|
Aggregate |
copy(RelTraitSet traitSet,
RelNode input,
boolean indicator,
ImmutableBitSet groupSet,
java.util.List<ImmutableBitSet> groupSets,
java.util.List<AggregateCall> aggCalls)
Deprecated.
|
abstract Aggregate |
copy(RelTraitSet traitSet,
RelNode input,
ImmutableBitSet groupSet,
java.util.List<ImmutableBitSet> groupSets,
java.util.List<AggregateCall> aggCalls)
Creates a copy of this aggregate.
|
protected RelDataType |
deriveRowType() |
static RelDataType |
deriveRowType(RelDataTypeFactory typeFactory,
RelDataType inputRowType,
boolean indicator,
ImmutableBitSet groupSet,
java.util.List<ImmutableBitSet> groupSets,
java.util.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.
|
java.util.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()
Deprecated.
|
java.util.List<Pair<AggregateCall,java.lang.String>> |
getNamedAggCalls()
Returns a list of calls to aggregate functions together with their output
field names.
|
static boolean |
isNotGrandTotal(Aggregate aggregate) |
private boolean |
isPredicate(RelNode input,
int index) |
static boolean |
isSimple(Aggregate aggregate) |
boolean |
isValid(Litmus litmus,
RelNode.Context context)
Returns whether this relational expression is valid.
|
static boolean |
noIndicator(Aggregate aggregate)
Deprecated.
|
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, replaceInput
accept, 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, toString
@Deprecated public static final com.google.common.base.Predicate<Aggregate> IS_SIMPLE
@Deprecated public static final com.google.common.base.Predicate<Aggregate> NO_INDICATOR
@Deprecated public static final com.google.common.base.Predicate<Aggregate> IS_NOT_GRAND_TOTAL
@Deprecated public final boolean indicator
protected final java.util.List<AggregateCall> aggCalls
protected final ImmutableBitSet groupSet
public final com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets
protected Aggregate(RelOptCluster cluster, RelTraitSet traitSet, RelNode input, ImmutableBitSet groupSet, java.util.List<ImmutableBitSet> groupSets, java.util.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
- ClustertraitSet
- Trait setinput
- Input relational expressiongroupSet
- Bit set of grouping fieldsgroupSets
- List of all grouping sets; null for just groupSet
aggCalls
- Collection of calls to aggregate functions@Deprecated protected Aggregate(RelOptCluster cluster, RelTraitSet traits, RelNode child, boolean indicator, ImmutableBitSet groupSet, java.util.List<ImmutableBitSet> groupSets, java.util.List<AggregateCall> aggCalls)
protected Aggregate(RelInput input)
public static boolean isSimple(Aggregate aggregate)
public static void checkIndicator(boolean indicator)
indicator
is removed,
before 2.0.public static boolean isNotGrandTotal(Aggregate aggregate)
@Deprecated public static boolean noIndicator(Aggregate aggregate)
private boolean isPredicate(RelNode input, int index)
public final RelNode copy(RelTraitSet traitSet, java.util.List<RelNode> inputs)
RelNode
Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.
copy
in interface RelNode
copy
in class AbstractRelNode
traitSet
- Trait setinputs
- Inputspublic abstract Aggregate copy(RelTraitSet traitSet, RelNode input, ImmutableBitSet groupSet, java.util.List<ImmutableBitSet> groupSets, java.util.List<AggregateCall> aggCalls)
traitSet
- Traitsinput
- InputgroupSet
- Bit set of grouping fieldsgroupSets
- List of all grouping sets; null for just groupSet
aggCalls
- 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)
@Deprecated public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, java.util.List<ImmutableBitSet> groupSets, java.util.List<AggregateCall> aggCalls)
public java.util.List<AggregateCall> getAggCallList()
public java.util.List<Pair<AggregateCall,java.lang.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.
@Deprecated public int getIndicatorCount()
Always zero.
public ImmutableBitSet getGroupSet()
public com.google.common.collect.ImmutableList<ImmutableBitSet> getGroupSets()
groupSet
public RelWriter explainTerms(RelWriter pw)
AbstractRelNode
super.explainTerms
, then call the
RelWriter.input(String, RelNode)
and
RelWriterImpl.item(String, Object)
methods for each input and attribute.explainTerms
in class SingleRel
pw
- Plan writerpublic double estimateRowCount(RelMetadataQuery mq)
RelNode
NOTE 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 RelNode
estimateRowCount
in class SingleRel
mq
- Metadata querypublic RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
RelNode
NOTE 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 RelNode
computeSelfCost
in class AbstractRelNode
planner
- Planner for cost calculationmq
- Metadata queryprotected RelDataType deriveRowType()
deriveRowType
in class SingleRel
public static RelDataType deriveRowType(RelDataTypeFactory typeFactory, RelDataType inputRowType, boolean indicator, ImmutableBitSet groupSet, java.util.List<ImmutableBitSet> groupSets, java.util.List<AggregateCall> aggCalls)
Aggregate
before it exists.typeFactory
- Type factoryinputRowType
- Input row typeindicator
- Deprecated, always falsegroupSet
- Bit set of grouping fieldsgroupSets
- List of all grouping sets; null for just groupSet
aggCalls
- Collection of calls to aggregate functionsprivate static boolean allContain(java.util.List<ImmutableBitSet> groupSets, int groupKey)
public boolean isValid(Litmus litmus, RelNode.Context context)
RelNode
If 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 RelNode
isValid
in class AbstractRelNode
litmus
- 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–2019 The Apache Software Foundation. All rights reserved.