org.eigenbase.sql2rel
Class SqlToRelConverter.Blackboard

java.lang.Object
  extended by org.eigenbase.sql2rel.SqlToRelConverter.Blackboard
All Implemented Interfaces:
SqlVisitor<RexNode>, SqlRexContext
Enclosing class:
SqlToRelConverter

protected class SqlToRelConverter.Blackboard
extends Object
implements SqlRexContext, SqlVisitor<RexNode>

Workspace for translating an individual SELECT statement (or sub-SELECT).


Field Summary
(package private)  SqlToRelConverter.AggConverter agg
          Workspace for building aggregates.
private  List<SqlMonotonicity> columnMonotonicities
           
(package private)  List<RelNode> cursors
           
private  RelNode[] inputs
           
private  Map<String,RexNode> mapCorrelateVariableToRexNode
           
private  Map<RelNode,Map<Integer,Integer>> mapRootRelToFieldProjection
          Project the groupby expressions out of the root of this sub-select.
private  Map<SqlNode,RexNode> mapSubqueryToExpr
          Maps IN and EXISTS sub-queries to the expressions which will be used to access them.
private  Map<String,RexNode> nameToNodeMap
           
 RelNode root
           
 SqlValidatorScope scope
          Collection of RelNode objects which correspond to a SELECT statement.
private  List<SqlNode> subqueryList
          List of IN and EXISTS nodes inside this SELECT statement (but not inside sub-queries).
private  boolean subqueryNeedsOuterJoin
           
private  List<RelDataTypeField> systemFieldList
           
 
Constructor Summary
protected SqlToRelConverter.Blackboard(SqlValidatorScope scope, Map<String,RexNode> nameToNodeMap)
          Creates a Blackboard.
 
Method Summary
 void adjustSubqueries(int index, int count)
          Shifts the expressions used to reference subqueries to the right.
 RexNode convertExpression(SqlNode expr)
          Converts an expression from SqlNode to RexNode format.
 RexNode convertInterval(SqlIntervalQualifier intervalQualifier)
           
 RexNode convertLiteral(SqlLiteral literal)
          Converts a literal.
 void flatten(RelNode[] rels, int systemFieldCount, int[] start, List<Pair<RelNode,Integer>> relOffsetList)
           
 List<SqlMonotonicity> getColumnMonotonicities()
           
 DefaultValueFactory getDefaultValueFactory()
          Returns the factory which supplies default values for INSERT, UPDATE, and NEW.
 RexBuilder getRexBuilder()
          Returns the RexBuilder to use to create RexNode objects.
(package private)  RelDataTypeField getRootField(RexInputRef inputRef)
           
 RexRangeRef getSubqueryExpr(SqlCall call)
          Returns the expression used to access a given IN or EXISTS sub-query.
 RelDataTypeFactory getTypeFactory()
          Returns the type factory.
 SqlValidator getValidator()
          Returns the validator.
private  boolean isConvertedSubq(RexNode rex)
          Determines whether a RexNode corresponds to a subquery that's been converted to a constant.
(package private)  RexNode lookup(int offset, SqlToRelConverter.LookupContext lookupContext)
          Creates an expression with which to reference the expression whose offset in its from-list is offset.
(package private)  RexNode lookupExp(String name)
          Returns an expression with which to reference a from-list item.
 RexNode register(RelNode rel, JoinRelType joinType)
           
 RexNode register(RelNode rel, JoinRelType joinType, RexNode[] leftJoinKeysForIn)
          Registers a relational expression.
(package private)  void registerSubquery(SqlNode node)
           
(package private)  RelNode[] retrieveCursors()
           
 void setDataset(String datasetName)
          Notifies this Blackboard that the root just set using setRoot(RelNode, boolean) was derived using dataset substitution.
(package private)  void setRoot(RelNode[] inputs)
           
private  void setRoot(RelNode[] inputs, RelNode root, boolean hasSystemFields)
           
 void setRoot(RelNode root, boolean leaf)
          Sets a new root relational expression, as the translation process backs its way further up the tree.
 RexNode visit(SqlCall call)
          Visits a call to a SqlOperator.
 RexNode visit(SqlDataTypeSpec type)
          Visits a datatype specification.
 RexNode visit(SqlDynamicParam param)
          Visits a dynamic parameter.
 RexNode visit(SqlIdentifier id)
          Visits an identifier.
 RexNode visit(SqlIntervalQualifier intervalQualifier)
          Visits an interval qualifier
 RexNode visit(SqlLiteral literal)
          Visits a literal.
 RexNode 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

scope

public final SqlValidatorScope scope
Collection of RelNode objects which correspond to a SELECT statement.


nameToNodeMap

private final Map<String,RexNode> nameToNodeMap

root

public RelNode root

inputs

private RelNode[] inputs

mapCorrelateVariableToRexNode

private final Map<String,RexNode> mapCorrelateVariableToRexNode

cursors

List<RelNode> cursors

subqueryList

private final List<SqlNode> subqueryList
List of IN and EXISTS nodes inside this SELECT statement (but not inside sub-queries).


mapSubqueryToExpr

private final Map<SqlNode,RexNode> mapSubqueryToExpr
Maps IN and EXISTS sub-queries to the expressions which will be used to access them.


subqueryNeedsOuterJoin

private boolean subqueryNeedsOuterJoin

agg

SqlToRelConverter.AggConverter agg
Workspace for building aggregates.


mapRootRelToFieldProjection

private final Map<RelNode,Map<Integer,Integer>> mapRootRelToFieldProjection
Project the groupby expressions out of the root of this sub-select. Subqueries can reference group by expressions projected from the "right" to the subquery.


columnMonotonicities

private final List<SqlMonotonicity> columnMonotonicities

systemFieldList

private final List<RelDataTypeField> systemFieldList
Constructor Detail

SqlToRelConverter.Blackboard

protected SqlToRelConverter.Blackboard(SqlValidatorScope scope,
                                       Map<String,RexNode> nameToNodeMap)
Creates a Blackboard.

Parameters:
scope - Name-resolution scope for expressions validated within this query. Can be null if this Blackboard is for a leaf node, say
nameToNodeMap - Map which translates the expression to map a given parameter into, if translating expressions; null otherwise
Method Detail

register

public RexNode register(RelNode rel,
                        JoinRelType joinType)

register

public RexNode register(RelNode rel,
                        JoinRelType joinType,
                        RexNode[] leftJoinKeysForIn)
Registers a relational expression.

Parameters:
rel - Relational expression
joinType - Join type
leftJoinKeysForIn - LHS of IN clause, or null for expressions other than IN
Returns:
Expression with which to refer to the row (or partial row) coming from this relational expression's side of the join. rchen 2006-08-17: temporarily translate select * from X where a not in (select b form Y); to select X.* from X, (select distinct b from Y) where not (a = b);

setRoot

public void setRoot(RelNode root,
                    boolean leaf)
Sets a new root relational expression, as the translation process backs its way further up the tree.

Parameters:
root - New root relational expression
leaf - Whether the relational expression is a leaf, that is, derived from an atomic relational expression such as a table name in the from clause, or the projection on top of a select-subquery. In particular, relational expressions derived from JOIN operators are not leaves, but set expressions are.

setRoot

private void setRoot(RelNode[] inputs,
                     RelNode root,
                     boolean hasSystemFields)

setDataset

public void setDataset(String datasetName)
Notifies this Blackboard that the root just set using setRoot(RelNode, boolean) was derived using dataset substitution.

The default implementation is not interested in such notifications, and does nothing.

Parameters:
datasetName - Dataset name

setRoot

void setRoot(RelNode[] inputs)

lookupExp

RexNode lookupExp(String name)
Returns an expression with which to reference a from-list item.

Parameters:
name - the alias of the from item
Returns:
a RexFieldAccess or RexRangeRef, or null if not found

lookup

RexNode lookup(int offset,
               SqlToRelConverter.LookupContext lookupContext)
Creates an expression with which to reference the expression whose offset in its from-list is offset.


getRootField

RelDataTypeField getRootField(RexInputRef inputRef)

flatten

public void flatten(RelNode[] rels,
                    int systemFieldCount,
                    int[] start,
                    List<Pair<RelNode,Integer>> relOffsetList)

registerSubquery

void registerSubquery(SqlNode node)

retrieveCursors

RelNode[] retrieveCursors()

convertExpression

public RexNode convertExpression(SqlNode expr)
Description copied from interface: SqlRexContext
Converts an expression from SqlNode to RexNode format.

Specified by:
convertExpression in interface SqlRexContext
Parameters:
expr - Expression to translate
Returns:
Converted expression

isConvertedSubq

private boolean isConvertedSubq(RexNode rex)
Determines whether a RexNode corresponds to a subquery that's been converted to a constant.

Parameters:
rex - the expression to be examined
Returns:
true if the expression is a dynamic parameter, a literal, or a literal that is being cast

getRexBuilder

public RexBuilder getRexBuilder()
Description copied from interface: SqlRexContext
Returns the RexBuilder to use to create RexNode objects.

Specified by:
getRexBuilder in interface SqlRexContext

getSubqueryExpr

public RexRangeRef getSubqueryExpr(SqlCall call)
Description copied from interface: SqlRexContext
Returns the expression used to access a given IN or EXISTS sub-query.

Specified by:
getSubqueryExpr in interface SqlRexContext
Parameters:
call - IN or EXISTS expression
Returns:
Expression used to access current row of sub-query

getTypeFactory

public RelDataTypeFactory getTypeFactory()
Description copied from interface: SqlRexContext
Returns the type factory.

Specified by:
getTypeFactory in interface SqlRexContext

getDefaultValueFactory

public DefaultValueFactory getDefaultValueFactory()
Description copied from interface: SqlRexContext
Returns the factory which supplies default values for INSERT, UPDATE, and NEW.

Specified by:
getDefaultValueFactory in interface SqlRexContext

getValidator

public SqlValidator getValidator()
Description copied from interface: SqlRexContext
Returns the validator.

Specified by:
getValidator in interface SqlRexContext

convertLiteral

public RexNode convertLiteral(SqlLiteral literal)
Description copied from interface: SqlRexContext
Converts a literal.

Specified by:
convertLiteral in interface SqlRexContext

convertInterval

public RexNode convertInterval(SqlIntervalQualifier intervalQualifier)

visit

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

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

visit

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

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

visit

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

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

visit

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

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

visit

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

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

visit

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

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

visit

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

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

adjustSubqueries

public void adjustSubqueries(int index,
                             int count)
Shifts the expressions used to reference subqueries to the right. Moves any reference ≥ index count places to the right.

Parameters:
index - Position where new expression was inserted
count - Number of new expressions inserted

getColumnMonotonicities

public List<SqlMonotonicity> getColumnMonotonicities()