public static class SqlSplittableAggFunction.CountSplitter extends java.lang.Object implements SqlSplittableAggFunction
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(*).
SqlSplittableAggFunction.AbstractSumSplitter, SqlSplittableAggFunction.CountSplitter, SqlSplittableAggFunction.Registry<E>, SqlSplittableAggFunction.SelfSplitter, SqlSplittableAggFunction.Sum0Splitter, SqlSplittableAggFunction.SumSplitter
Modifier and Type | Field and Description |
---|---|
static SqlSplittableAggFunction.CountSplitter |
INSTANCE |
Constructor and Description |
---|
CountSplitter() |
Modifier and Type | Method and Description |
---|---|
AggregateCall |
merge(AggregateCall top,
AggregateCall bottom)
Merge top and bottom aggregate calls into a single aggregate call,
if they are legit to merge.
|
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.
|
public static final SqlSplittableAggFunction.CountSplitter INSTANCE
public AggregateCall split(AggregateCall aggregateCall, Mappings.TargetMapping mapping)
split
in interface SqlSplittableAggFunction
public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e)
SqlSplittableAggFunction
other
in interface SqlSplittableAggFunction
public AggregateCall topSplit(RexBuilder rexBuilder, SqlSplittableAggFunction.Registry<RexNode> extra, int offset, RelDataType inputRowType, AggregateCall aggregateCall, int leftSubTotal, int rightSubTotal)
SqlSplittableAggFunction
Most implementations will add a single aggregate call to
aggCalls
, and return a RexInputRef
that points to it.
topSplit
in interface SqlSplittableAggFunction
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-totalpublic RexNode singleton(RexBuilder rexBuilder, RelDataType inputRowType, AggregateCall aggregateCall)
For example, if there is one row:
SUM(x)
is x
MIN(x)
is x
MAX(x)
is x
COUNT(x)
is CASE WHEN x IS NOT NULL THEN 1 ELSE 0 END 1
which can be simplified to 1
if x
is never null
COUNT(*)
is 1
COUNT(*)
, and COUNT
applied to all NOT NULL arguments,
become 1
; otherwise
CASE WHEN arg0 IS NOT NULL THEN 1 ELSE 0 END
.
singleton
in interface SqlSplittableAggFunction
rexBuilder
- Rex builderinputRowType
- Input row typeaggregateCall
- Aggregate callpublic AggregateCall merge(AggregateCall top, AggregateCall bottom)
SqlSplittableAggFunction
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.
merge
in interface SqlSplittableAggFunction
top
- top aggregate callbottom
- bottom aggregate callCopyright © 2012–2019 The Apache Software Foundation. All rights reserved.