Package org.apache.calcite.sql
Class SqlSplittableAggFunction.CountSplitter
java.lang.Object
org.apache.calcite.sql.SqlSplittableAggFunction.CountSplitter
- All Implemented Interfaces:
SqlSingletonAggFunction
,SqlSplittableAggFunction
- Enclosing interface:
SqlSplittableAggFunction
public static class SqlSplittableAggFunction.CountSplitter
extends Object
implements SqlSplittableAggFunction
Splitting strategy for
COUNT
.
COUNT splits into itself followed by SUM. (Actually SUM0, because the total needs to be 0, not null, if there are 0 rows.) This rule works for any number of arguments to COUNT, including COUNT(*).
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.calcite.sql.SqlSplittableAggFunction
SqlSplittableAggFunction.AbstractSumSplitter, SqlSplittableAggFunction.CountSplitter, SqlSplittableAggFunction.Registry<E>, SqlSplittableAggFunction.SelfSplitter, SqlSplittableAggFunction.Sum0Splitter, SqlSplittableAggFunction.SumSplitter
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription@Nullable AggregateCall
merge
(AggregateCall top, AggregateCall bottom) Merge top and bottom aggregate calls into a single aggregate call, if they are legit to merge.@Nullable 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.singleton
(RexBuilder rexBuilder, RelDataType inputRowType, AggregateCall aggregateCall) Generates an expression for the value of the aggregate function when applied to a single row.split
(AggregateCall aggregateCall, Mappings.TargetMapping mapping) 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.
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
CountSplitter
public CountSplitter()
-
-
Method Details
-
split
- Specified by:
split
in interfaceSqlSplittableAggFunction
-
other
Description copied from interface:SqlSplittableAggFunction
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.- Specified by:
other
in interfaceSqlSplittableAggFunction
-
topSplit
public AggregateCall topSplit(RexBuilder rexBuilder, SqlSplittableAggFunction.Registry<RexNode> extra, int offset, RelDataType inputRowType, AggregateCall aggregateCall, int leftSubTotal, int rightSubTotal) Description copied from interface:SqlSplittableAggFunction
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.- Specified by:
topSplit
in interfaceSqlSplittableAggFunction
- 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
public 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 1GROUPING(deptno)
if 0 ifdeptno
is being grouped, 1 otherwise
COUNT(*)
, andCOUNT
applied to all NOT NULL arguments, become1
; otherwiseCASE WHEN arg0 IS NOT NULL THEN 1 ELSE 0 END
.- Specified by:
singleton
in interfaceSqlSingletonAggFunction
- Parameters:
rexBuilder
- Rex builderinputRowType
- Input row typeaggregateCall
- Aggregate call- Returns:
- Expression for single row
-
merge
Description copied from interface:SqlSplittableAggFunction
Merge top and bottom aggregate calls into a single aggregate call, if they are legit to merge.SUM of SUM becomes SUM; SUM of COUNT becomes COUNT; MAX of MAX becomes MAX; MIN of MIN becomes MIN. AVG of AVG would not match, nor would COUNT of COUNT.
- Specified by:
merge
in interfaceSqlSplittableAggFunction
- Parameters:
top
- top aggregate callbottom
- bottom aggregate call- Returns:
- Merged aggregate call, null if fails to merge aggregate calls
-