Package org.apache.calcite.sql
Interface SqlSplittableAggFunction
-
- All Known Implementing Classes:
SqlSplittableAggFunction.AbstractSumSplitter
,SqlSplittableAggFunction.CountSplitter
,SqlSplittableAggFunction.SelfSplitter
,SqlSplittableAggFunction.Sum0Splitter
,SqlSplittableAggFunction.SumSplitter
public interface SqlSplittableAggFunction
Aggregate function that can be split into partial aggregates.For example,
COUNT(x)
can be split intoCOUNT(x)
on subsets followed bySUM
to combine those counts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
SqlSplittableAggFunction.AbstractSumSplitter
Common splitting strategy forSUM
andSUM0
functions.static class
SqlSplittableAggFunction.CountSplitter
Splitting strategy forCOUNT
.static interface
SqlSplittableAggFunction.Registry<E>
Collection in which one can register an element.static class
SqlSplittableAggFunction.SelfSplitter
Aggregate function that splits into two applications of itself.static class
SqlSplittableAggFunction.Sum0Splitter
Splitting strategy forSUM0
function.static class
SqlSplittableAggFunction.SumSplitter
Splitting strategy forSUM
function.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AggregateCall
other(RelDataTypeFactory typeFactory, AggregateCall e)
Called to generate an aggregate for the other side of the join than the side aggregate call's arguments come from.RexNode
singleton(RexBuilder rexBuilder, RelDataType inputRowType, AggregateCall aggregateCall)
Generates an expression for the value of the aggregate function when applied to a single row.AggregateCall
split(AggregateCall aggregateCall, Mappings.TargetMapping mapping)
AggregateCall
topSplit(RexBuilder rexBuilder, SqlSplittableAggFunction.Registry<RexNode> extra, int offset, RelDataType inputRowType, AggregateCall aggregateCall, int leftSubTotal, int rightSubTotal)
Generates an aggregate call to merge sub-totals.
-
-
-
Method Detail
-
split
AggregateCall split(AggregateCall aggregateCall, Mappings.TargetMapping mapping)
-
other
AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e)
Called to generate an aggregate for the other side of the join than the side aggregate call's arguments come from. Returns null if no aggregate is required.
-
topSplit
AggregateCall topSplit(RexBuilder rexBuilder, SqlSplittableAggFunction.Registry<RexNode> extra, int offset, RelDataType inputRowType, AggregateCall aggregateCall, int leftSubTotal, int rightSubTotal)
Generates an aggregate call to merge sub-totals.Most implementations will add a single aggregate call to
aggCalls
, and return aRexInputRef
that points to it.- Parameters:
rexBuilder
- Rex builderextra
- Place to define extra input expressionsoffset
- Offset due to grouping columns (and indicator columns if applicable)inputRowType
- Input row typeaggregateCall
- Source aggregate callleftSubTotal
- Ordinal of the sub-total coming from the left side of the join, or -1 if there is no such sub-totalrightSubTotal
- Ordinal of the sub-total coming from the right side of the join, or -1 if there is no such sub-total- Returns:
- Aggregate call
-
singleton
RexNode singleton(RexBuilder rexBuilder, RelDataType inputRowType, AggregateCall aggregateCall)
Generates an expression for the value of the aggregate function when applied to a single row.For example, if there is one row:
SUM(x)
isx
MIN(x)
isx
MAX(x)
isx
COUNT(x)
isCASE WHEN x IS NOT NULL THEN 1 ELSE 0 END 1
which can be simplified to1
ifx
is never nullCOUNT(*)
is 1
- Parameters:
rexBuilder
- Rex builderinputRowType
- Input row typeaggregateCall
- Aggregate call- Returns:
- Expression for single row
-
-