org.eigenbase.sql2rel
Class SqlToRelConverter.AggConverter

java.lang.Object
  extended by org.eigenbase.sql2rel.SqlToRelConverter.AggConverter
All Implemented Interfaces:
SqlVisitor<Void>
Enclosing class:
SqlToRelConverter

protected class SqlToRelConverter.AggConverter
extends Object
implements SqlVisitor<Void>

Converts expressions to aggregates.

Consider the expression SELECT deptno, SUM(2 * sal) FROM emp GROUP BY deptno Then


Field Summary
private  Map<AggregateCall,RexNode> aggCallMapping
           
private  List<AggregateCall> aggCalls
           
private  Map<SqlNode,RexNode> aggMapping
           
private  SqlToRelConverter.Blackboard bb
           
private  List<String> convertedInputExprNames
          Names of convertedInputExprs, where the expressions are simple mappings to input fields.
private  List<RexNode> convertedInputExprs
          Input expressions for the group columns and aggregates, in RexNode format.
private  SqlNodeList groupExprs
          The group-by expressions, in SqlNode format.
private  List<RexInputRef> inputRefs
           
private  Map<String,String> nameMap
           
 
Constructor Summary
SqlToRelConverter.AggConverter(SqlToRelConverter.Blackboard bb, SqlSelect select)
          Creates an AggConverter.
 
Method Summary
private  void addExpr(RexNode expr, String name)
          Adds an expression, deducing an appropriate name if possible.
 void addGroupExpr(SqlNode expr)
           
 List<AggregateCall> getAggCalls()
           
 List<RexNode> getPreExprs()
           
 List<String> getPreNames()
           
 RelDataTypeFactory getTypeFactory()
           
 RexNode lookupAggregates(SqlCall call)
           
 RexNode 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)
           
 Void visit(SqlCall call)
          Visits a call to a SqlOperator.
 Void visit(SqlDataTypeSpec type)
          Visits a datatype specification.
 Void visit(SqlDynamicParam param)
          Visits a dynamic parameter.
 Void visit(SqlIdentifier id)
          Visits an identifier.
 Void visit(SqlIntervalQualifier intervalQualifier)
          Visits an interval qualifier
 Void visit(SqlLiteral lit)
          Visits a literal.
 Void visit(SqlNodeList nodeList)
          Visits a list of SqlNode objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bb

private final SqlToRelConverter.Blackboard bb

nameMap

private final Map<String,String> nameMap

groupExprs

private final SqlNodeList groupExprs
The group-by expressions, in SqlNode format.


convertedInputExprs

private final List<RexNode> convertedInputExprs
Input expressions for the group columns and aggregates, in RexNode format. The first elements of the list correspond to the elements in groupExprs; the remaining elements are for aggregates.


convertedInputExprNames

private final List<String> convertedInputExprNames
Names of convertedInputExprs, where the expressions are simple mappings to input fields.


inputRefs

private final List<RexInputRef> inputRefs

aggCalls

private final List<AggregateCall> aggCalls

aggMapping

private final Map<SqlNode,RexNode> aggMapping

aggCallMapping

private final Map<AggregateCall,RexNode> aggCallMapping
Constructor Detail

SqlToRelConverter.AggConverter

public SqlToRelConverter.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 - Blackboard
select - Query being translated; provides context to give
Method Detail

addGroupExpr

public void addGroupExpr(SqlNode expr)

addExpr

private void addExpr(RexNode expr,
                     String name)
Adds an expression, deducing an appropriate name if possible.

Parameters:
expr - Expression
name - Suggested name

visit

public Void visit(SqlIdentifier id)
Description copied from interface: SqlVisitor
Visits an identifier.

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
id - identifier
See Also:
SqlIdentifier.accept(SqlVisitor)

visit

public Void visit(SqlNodeList nodeList)
Description copied from interface: SqlVisitor
Visits a list of SqlNode objects.

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
nodeList - list of nodes
See Also:
SqlNodeList.accept(SqlVisitor)

visit

public Void visit(SqlLiteral lit)
Description copied from interface: SqlVisitor
Visits a literal.

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
lit - Literal
See Also:
SqlLiteral.accept(SqlVisitor)

visit

public Void visit(SqlDataTypeSpec type)
Description copied from interface: SqlVisitor
Visits a datatype specification.

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
type - datatype specification
See Also:
SqlDataTypeSpec.accept(SqlVisitor)

visit

public Void visit(SqlDynamicParam param)
Description copied from interface: SqlVisitor
Visits a dynamic parameter.

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
param - Dynamic parameter
See Also:
SqlDynamicParam.accept(SqlVisitor)

visit

public Void visit(SqlIntervalQualifier intervalQualifier)
Description copied from interface: SqlVisitor
Visits an interval qualifier

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
intervalQualifier - Interval qualifier
See Also:
SqlIntervalQualifier.accept(SqlVisitor)

visit

public Void visit(SqlCall call)
Description copied from interface: SqlVisitor
Visits a call to a SqlOperator.

Specified by:
visit in interface SqlVisitor<Void>
Parameters:
call - Call
See Also:
SqlCall.accept(SqlVisitor)

lookupOrCreateGroupExpr

private int lookupOrCreateGroupExpr(RexNode expr)

lookupGroupExpr

public RexNode 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.


lookupAggregates

public RexNode lookupAggregates(SqlCall call)

getPreExprs

public List<RexNode> getPreExprs()

getPreNames

public List<String> getPreNames()

getAggCalls

public List<AggregateCall> getAggCalls()

getTypeFactory

public RelDataTypeFactory getTypeFactory()