Package org.apache.calcite.sql2rel
Class SqlToRelConverter.HistogramShuttle
- java.lang.Object
-
- org.apache.calcite.rex.RexShuttle
-
- org.apache.calcite.sql2rel.SqlToRelConverter.HistogramShuttle
-
- All Implemented Interfaces:
RexVisitor<RexNode>
- Enclosing class:
- SqlToRelConverter
private class SqlToRelConverter.HistogramShuttle extends RexShuttle
Shuttle which walks over a tree ofRexNode
s 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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
distinct
(package private) static boolean
ENABLE_HISTOGRAM_AGG
Whether to convert calls to MIN(x) to HISTOGRAM_MIN(HISTOGRAM(x)).private RexWindowBound
lowerBound
private com.google.common.collect.ImmutableList<RexFieldCollation>
orderKeys
private java.util.List<RexNode>
partitionKeys
private RexWindowBound
upperBound
private SqlWindow
window
-
Constructor Summary
Constructors Constructor Description HistogramShuttle(java.util.List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, SqlWindow window, boolean distinct)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.apache.calcite.rex.RexShuttle
apply, apply, apply, mutate, visitArray, visitCorrelVariable, visitDynamicParam, visitFieldAccess, visitFieldCollations, visitInputRef, visitList, visitList, visitLiteral, visitLocalRef, visitOver, visitPatternFieldRef, visitRangeRef, visitSubQuery, visitTableInputRef, visitWindow
-
-
-
-
Field Detail
-
ENABLE_HISTOGRAM_AGG
static final boolean ENABLE_HISTOGRAM_AGG
Whether to convert calls to MIN(x) to HISTOGRAM_MIN(HISTOGRAM(x)). Histograms allow rolling computation, but require more space.- See Also:
- Constant Field Values
-
partitionKeys
private final java.util.List<RexNode> partitionKeys
-
orderKeys
private final com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys
-
lowerBound
private final RexWindowBound lowerBound
-
upperBound
private final RexWindowBound upperBound
-
window
private final SqlWindow window
-
distinct
private final boolean distinct
-
-
Constructor Detail
-
HistogramShuttle
HistogramShuttle(java.util.List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, SqlWindow window, boolean distinct)
-
-
Method Detail
-
visitCall
public RexNode visitCall(RexCall call)
- Specified by:
visitCall
in interfaceRexVisitor<RexNode>
- Overrides:
visitCall
in classRexShuttle
-
getHistogramOp
SqlFunction getHistogramOp(SqlAggFunction aggFunction)
Returns the histogram operator corresponding to a given aggregate function.For example,
getHistogramOp (
returnsSqlStdOperatorTable.MIN
}SqlStdOperatorTable.HISTOGRAM_MIN
.- 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.
-
-