Package org.apache.calcite.sql2rel
Class SqlToRelConverter.AggConverter
- java.lang.Object
-
- org.apache.calcite.sql2rel.SqlToRelConverter.AggConverter
-
- All Implemented Interfaces:
SqlVisitor<java.lang.Void>
- Enclosing class:
- SqlToRelConverter
protected class SqlToRelConverter.AggConverter extends java.lang.Object implements SqlVisitor<java.lang.Void>
Converts expressions to aggregates.Consider the expression
SELECT deptno, SUM(2 * sal) FROM emp GROUP BY deptno
Then:
- groupExprs = {SqlIdentifier(deptno)}
- convertedInputExprs = {RexInputRef(deptno), 2 * RefInputRef(sal)}
- inputRefs = {RefInputRef(#0), RexInputRef(#1)}
- aggCalls = {AggCall(SUM, {1})}
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<AggregateCall,RexNode>
aggCallMapping
private java.util.List<AggregateCall>
aggCalls
Expressions to be evaluated as rows are being placed into the aggregate's hash table.private java.util.Map<SqlNode,RexNode>
aggMapping
AggregatingSelectScope
aggregatingSelectScope
private java.util.Map<SqlNode,Ord<AuxiliaryConverter>>
auxiliaryGroupExprs
The auxiliary group-by expressions.private SqlToRelConverter.Blackboard
bb
private java.util.List<Pair<RexNode,java.lang.String>>
convertedInputExprs
Input expressions for the group columns and aggregates, inRexNode
format.private SqlNodeList
groupExprs
The group-by expressions, inSqlNode
format.private boolean
inOver
Are we directly inside a windowed aggregate?private java.util.Map<java.lang.String,java.lang.String>
nameMap
-
Constructor Summary
Constructors Constructor Description AggConverter(SqlToRelConverter.Blackboard bb, SqlSelect select)
Creates an AggConverter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addAuxiliaryGroupExpr(SqlNode node, int index, AuxiliaryConverter converter)
private void
addExpr(RexNode expr, java.lang.String name)
Adds an expression, deducing an appropriate name if possible.int
addGroupExpr(SqlNode expr)
java.util.List<AggregateCall>
getAggCalls()
java.util.List<Pair<RexNode,java.lang.String>>
getPreExprs()
RelDataTypeFactory
getTypeFactory()
RexNode
lookupAggregates(SqlCall call)
int
lookupGroupExpr(SqlNode expr)
If an expression is structurally identical to one of the group-by expressions, returns a reference to the expression, otherwise returns null.private int
lookupOrCreateGroupExpr(RexNode expr)
private void
translateAgg(SqlCall call)
private void
translateAgg(SqlCall call, SqlNode filter, SqlNodeList orderList, SqlCall outerCall)
java.lang.Void
visit(SqlCall call)
Visits a call to aSqlOperator
.java.lang.Void
visit(SqlDataTypeSpec type)
Visits a datatype specification.java.lang.Void
visit(SqlDynamicParam param)
Visits a dynamic parameter.java.lang.Void
visit(SqlIdentifier id)
Visits an identifier.java.lang.Void
visit(SqlIntervalQualifier intervalQualifier)
Visits an interval qualifierjava.lang.Void
visit(SqlLiteral lit)
Visits a literal.java.lang.Void
visit(SqlNodeList nodeList)
Visits a list ofSqlNode
objects.
-
-
-
Field Detail
-
bb
private final SqlToRelConverter.Blackboard bb
-
aggregatingSelectScope
public final AggregatingSelectScope aggregatingSelectScope
-
nameMap
private final java.util.Map<java.lang.String,java.lang.String> nameMap
-
groupExprs
private final SqlNodeList groupExprs
The group-by expressions, inSqlNode
format.
-
auxiliaryGroupExprs
private final java.util.Map<SqlNode,Ord<AuxiliaryConverter>> auxiliaryGroupExprs
The auxiliary group-by expressions.
-
convertedInputExprs
private final java.util.List<Pair<RexNode,java.lang.String>> convertedInputExprs
Input expressions for the group columns and aggregates, inRexNode
format. The first elements of the list correspond to the elements ingroupExprs
; the remaining elements are for aggregates. The right field of each pair is the name of the expression, where the expressions are simple mappings to input fields.
-
aggCalls
private final java.util.List<AggregateCall> aggCalls
Expressions to be evaluated as rows are being placed into the aggregate's hash table. This is when group functions such as TUMBLE cause rows to be expanded.
-
aggCallMapping
private final java.util.Map<AggregateCall,RexNode> aggCallMapping
-
inOver
private boolean inOver
Are we directly inside a windowed aggregate?
-
-
Constructor Detail
-
AggConverter
public AggConverter(SqlToRelConverter.Blackboard bb, SqlSelect select)
Creates an AggConverter.The
select
parameter provides enough context to name aggregate calls which are top-level select list items.- Parameters:
bb
- Blackboardselect
- Query being translated; provides context to give
-
-
Method Detail
-
addGroupExpr
public int addGroupExpr(SqlNode expr)
-
addAuxiliaryGroupExpr
void addAuxiliaryGroupExpr(SqlNode node, int index, AuxiliaryConverter converter)
-
addExpr
private void addExpr(RexNode expr, java.lang.String name)
Adds an expression, deducing an appropriate name if possible.- Parameters:
expr
- Expressionname
- Suggested name
-
visit
public java.lang.Void visit(SqlIdentifier id)
Description copied from interface:SqlVisitor
Visits an identifier.- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
id
- identifier- See Also:
SqlIdentifier.accept(SqlVisitor)
-
visit
public java.lang.Void visit(SqlNodeList nodeList)
Description copied from interface:SqlVisitor
Visits a list ofSqlNode
objects.- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
nodeList
- list of nodes- See Also:
SqlNodeList.accept(SqlVisitor)
-
visit
public java.lang.Void visit(SqlLiteral lit)
Description copied from interface:SqlVisitor
Visits a literal.- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
lit
- Literal- See Also:
SqlLiteral.accept(SqlVisitor)
-
visit
public java.lang.Void visit(SqlDataTypeSpec type)
Description copied from interface:SqlVisitor
Visits a datatype specification.- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
type
- datatype specification- See Also:
SqlDataTypeSpec.accept(SqlVisitor)
-
visit
public java.lang.Void visit(SqlDynamicParam param)
Description copied from interface:SqlVisitor
Visits a dynamic parameter.- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
param
- Dynamic parameter- See Also:
SqlDynamicParam.accept(SqlVisitor)
-
visit
public java.lang.Void visit(SqlIntervalQualifier intervalQualifier)
Description copied from interface:SqlVisitor
Visits an interval qualifier- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
intervalQualifier
- Interval qualifier- See Also:
SqlIntervalQualifier.accept(SqlVisitor)
-
visit
public java.lang.Void visit(SqlCall call)
Description copied from interface:SqlVisitor
Visits a call to aSqlOperator
.- Specified by:
visit
in interfaceSqlVisitor<java.lang.Void>
- Parameters:
call
- Call- See Also:
SqlCall.accept(SqlVisitor)
-
translateAgg
private void translateAgg(SqlCall call)
-
translateAgg
private void translateAgg(SqlCall call, SqlNode filter, SqlNodeList orderList, SqlCall outerCall)
-
lookupOrCreateGroupExpr
private int lookupOrCreateGroupExpr(RexNode expr)
-
lookupGroupExpr
public int lookupGroupExpr(SqlNode expr)
If an expression is structurally identical to one of the group-by expressions, returns a reference to the expression, otherwise returns null.
-
getAggCalls
public java.util.List<AggregateCall> getAggCalls()
-
getTypeFactory
public RelDataTypeFactory getTypeFactory()
-
-