Interface SqlSplittableAggFunction

All Superinterfaces:
SqlSingletonAggFunction
All Known Implementing Classes:
SqlSplittableAggFunction.AbstractSumSplitter, SqlSplittableAggFunction.CountSplitter, SqlSplittableAggFunction.SelfSplitter, SqlSplittableAggFunction.Sum0Splitter, SqlSplittableAggFunction.SumSplitter

public interface SqlSplittableAggFunction extends SqlSingletonAggFunction
Aggregate function that can be split into partial aggregates.

For example, COUNT(x) can be split into COUNT(x) on subsets followed by SUM to combine those counts.

  • Method Details

    • split

      AggregateCall split(AggregateCall aggregateCall, Mappings.TargetMapping mapping)
    • other

      @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. 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 a RexInputRef that points to it.

      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

      @Nullable AggregateCall merge(AggregateCall top, AggregateCall bottom)
      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.

      Parameters:
      top - top aggregate call
      bottom - bottom aggregate call
      Returns:
      Merged aggregate call, null if fails to merge aggregate calls