Class SqlSplittableAggFunction.AbstractSumSplitter

java.lang.Object
org.apache.calcite.sql.SqlSplittableAggFunction.AbstractSumSplitter
All Implemented Interfaces:
SqlSingletonAggFunction, SqlSplittableAggFunction
Direct Known Subclasses:
SqlSplittableAggFunction.Sum0Splitter, SqlSplittableAggFunction.SumSplitter
Enclosing interface:
SqlSplittableAggFunction

public abstract static class SqlSplittableAggFunction.AbstractSumSplitter extends Object implements SqlSplittableAggFunction
Common splitting strategy for SUM and SUM0 functions.
  • Constructor Details

    • AbstractSumSplitter

      public AbstractSumSplitter()
  • Method Details

    • singleton

      public RexNode singleton(RexBuilder rexBuilder, RelDataType inputRowType, AggregateCall aggregateCall)
      Description copied from interface: SqlSingletonAggFunction
      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) 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
      • GROUPING(deptno) if 0 if deptno is being grouped, 1 otherwise
      Specified by:
      singleton in interface SqlSingletonAggFunction
      Parameters:
      rexBuilder - Rex builder
      inputRowType - Input row type
      aggregateCall - Aggregate call
      Returns:
      Expression for single row
    • split

      public AggregateCall split(AggregateCall aggregateCall, Mappings.TargetMapping mapping)
      Specified by:
      split in interface SqlSplittableAggFunction
    • other

      public @Nullable AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e)
      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 interface SqlSplittableAggFunction
    • 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 a RexInputRef that points to it.

      Specified by:
      topSplit in interface SqlSplittableAggFunction
      Parameters:
      rexBuilder - Rex builder
      extra - Place to define extra input expressions
      offset - Offset due to grouping columns (and indicator columns if applicable)
      inputRowType - Input row type
      aggregateCall - Source aggregate call
      leftSubTotal - Ordinal of the sub-total coming from the left side of the join, or -1 if there is no such sub-total
      rightSubTotal - 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
    • merge

      public @Nullable AggregateCall merge(AggregateCall top, AggregateCall bottom)
      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 interface SqlSplittableAggFunction
      Parameters:
      top - top aggregate call
      bottom - bottom aggregate call
      Returns:
      Merged aggregate call, null if fails to merge aggregate calls
    • getMergeAggFunctionOfTopSplit

      protected abstract SqlAggFunction getMergeAggFunctionOfTopSplit()