Class SqlToRelConverter.HistogramShuttle

  • All Implemented Interfaces:
    RexVisitor<RexNode>
    Enclosing class:
    SqlToRelConverter

    private class SqlToRelConverter.HistogramShuttle
    extends RexShuttle
    Shuttle which walks over a tree of RexNodes and applies 'over' to all agg functions.

    This is necessary because the returned expression is not necessarily a call to an agg function. For example,

    AVG(x)

    becomes

    SUM(x) / COUNT(x)

    Any aggregate functions are converted to calls to the internal $Histogram aggregation function and accessors such as $HistogramMin; for example,

    MIN(x), MAX(x)

    are converted to

    $HistogramMin($Histogram(x)), $HistogramMax($Histogram(x))

    Common sub-expression elimination will ensure that only one histogram is computed.