org.eigenbase.sql2rel
Class SqlToRelConverter.HistogramShuttle

java.lang.Object
  extended by org.eigenbase.rex.RexShuttle
      extended by org.eigenbase.sql2rel.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 elmination will ensure that only one histogram is computed.


Field Summary
private  RexNode[] orderKeys
           
private  RexNode[] partitionKeys
           
private  SqlWindow window
           
 
Constructor Summary
SqlToRelConverter.HistogramShuttle(RexNode[] partitionKeys, RexNode[] orderKeys, SqlWindow window)
           
 
Method Summary
private  RelDataType computeHistogramType(RelDataType type)
          Returns the type for a histogram function.
(package private)  SqlFunction getHistogramOp(SqlAggFunction aggFunction)
          Returns the histogram operator corresponding to a given aggregate function.
 RexNode visitCall(RexCall call)
           
 
Methods inherited from class org.eigenbase.rex.RexShuttle
apply, apply, visitArray, visitCorrelVariable, visitDynamicParam, visitFieldAccess, visitInputRef, visitLiteral, visitLocalRef, visitOver, visitRangeRef, visitWindow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

partitionKeys

private final RexNode[] partitionKeys

orderKeys

private final RexNode[] orderKeys

window

private final SqlWindow window
Constructor Detail

SqlToRelConverter.HistogramShuttle

SqlToRelConverter.HistogramShuttle(RexNode[] partitionKeys,
                                   RexNode[] orderKeys,
                                   SqlWindow window)
Method Detail

visitCall

public RexNode visitCall(RexCall call)
Specified by:
visitCall in interface RexVisitor<RexNode>
Overrides:
visitCall in class RexShuttle

getHistogramOp

SqlFunction getHistogramOp(SqlAggFunction aggFunction)
Returns the histogram operator corresponding to a given aggregate function.

For example, getHistogramOp(SqlStdOperatorTable.minOperator} returns SqlStdOperatorTable.histogramMinFunction.

Parameters:
aggFunction - An aggregate function
Returns:
Its histogram function, or null

computeHistogramType

private RelDataType computeHistogramType(RelDataType type)
Returns the type for a histogram function. It is either the actual type or an an approximation to it.