Package org.apache.calcite.sql2rel
Class SqlToRelConverter.Blackboard
- java.lang.Object
-
- org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard
-
- All Implemented Interfaces:
SqlVisitor<RexNode>
,InitializerContext
,SqlRexContext
- Enclosing class:
- SqlToRelConverter
protected class SqlToRelConverter.Blackboard extends java.lang.Object implements SqlRexContext, SqlVisitor<RexNode>, InitializerContext
Workspace for translating an individual SELECT statement (or sub-SELECT).
-
-
Field Summary
Fields Modifier and Type Field Description (package private) SqlToRelConverter.AggConverter
agg
Workspace for building aggregates.private java.util.List<SqlMonotonicity>
columnMonotonicities
(package private) java.util.List<RelNode>
cursors
private InitializerExpressionFactory
initializerExpressionFactory
private java.util.List<RelNode>
inputs
private boolean
isPatternVarRef
private java.util.Map<CorrelationId,RexFieldAccess>
mapCorrelateToRex
private java.util.Map<RelNode,java.util.Map<java.lang.Integer,java.lang.Integer>>
mapRootRelToFieldProjection
Project the groupby expressions out of the root of this sub-select.private java.util.Map<java.lang.String,RexNode>
nameToNodeMap
RelNode
root
SqlValidatorScope
scope
Collection ofRelNode
objects which correspond to a SELECT statement.private java.util.Set<SqlToRelConverter.SubQuery>
subQueryList
List ofIN
andEXISTS
nodes inside thisSELECT
statement (but not inside sub-queries).private java.util.List<RelDataTypeField>
systemFieldList
(package private) boolean
top
(package private) SqlWindow
window
When converting window aggregate, we need to know if the window is guaranteed to be non-empty.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Blackboard(SqlValidatorScope scope, java.util.Map<java.lang.String,RexNode> nameToNodeMap, boolean top)
Creates a Blackboard.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RexNode
convertExpression(SqlNode expr)
RexNode
convertInterval(SqlIntervalQualifier intervalQualifier)
RexNode
convertLiteral(SqlLiteral literal)
Converts a literal.RexFieldCollation
convertSortExpression(SqlNode expr, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection)
Converts an item in an ORDER BY clause inside a window (OVER) clause, extracting DESC, NULLS LAST and NULLS FIRST flags first.void
flatten(java.util.List<RelNode> rels, int systemFieldCount, int[] start, java.util.List<Pair<RelNode,java.lang.Integer>> relOffsetList)
java.util.List<SqlMonotonicity>
getColumnMonotonicities()
int
getGroupCount()
If the operator call occurs in an aggregate query, returns the number of columns in the GROUP BY clause.InitializerExpressionFactory
getInitializerExpressionFactory()
Returns the factory which supplies default values for INSERT, UPDATE, and NEW.RexBuilder
getRexBuilder()
Returns theRexBuilder
to use to createRexNode
objects.(package private) RelDataTypeField
getRootField(RexInputRef inputRef)
(package private) SqlToRelConverter.SubQuery
getSubQuery(SqlNode expr)
RexRangeRef
getSubQueryExpr(SqlCall call)
Returns the expression used to access a given IN or EXISTSsub-query
.RelDataTypeFactory
getTypeFactory()
Returns the type factory.SqlValidator
getValidator()
Returns the validator.private boolean
isConvertedSubq(RexNode rex)
Determines whether a RexNode corresponds to a sub-query 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 isoffset
.(package private) Pair<RexNode,java.util.Map<java.lang.String,java.lang.Integer>>
lookupExp(SqlQualified qualified)
Returns an expression with which to reference a from-list item.RexNode
register(RelNode rel, JoinRelType joinType)
RexNode
register(RelNode rel, JoinRelType joinType, java.util.List<RexNode> leftKeys)
Registers a relational expression.(package private) void
registerSubQuery(SqlNode node, RelOptUtil.Logic logic)
(package private) com.google.common.collect.ImmutableList<RelNode>
retrieveCursors()
void
setDataset(java.lang.String datasetName)
Notifies this Blackboard that the root just set usingsetRoot(RelNode, boolean)
was derived using dataset substitution.void
setPatternVarRef(boolean isVarRef)
(package private) void
setRoot(java.util.List<RelNode> inputs)
private void
setRoot(java.util.List<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 aSqlOperator
.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 qualifierRexNode
visit(SqlLiteral literal)
Visits a literal.RexNode
visit(SqlNodeList nodeList)
Visits a list ofSqlNode
objects.
-
-
-
Field Detail
-
scope
public final SqlValidatorScope scope
Collection ofRelNode
objects which correspond to a SELECT statement.
-
nameToNodeMap
private final java.util.Map<java.lang.String,RexNode> nameToNodeMap
-
root
public RelNode root
-
inputs
private java.util.List<RelNode> inputs
-
mapCorrelateToRex
private final java.util.Map<CorrelationId,RexFieldAccess> mapCorrelateToRex
-
isPatternVarRef
private boolean isPatternVarRef
-
cursors
final java.util.List<RelNode> cursors
-
subQueryList
private final java.util.Set<SqlToRelConverter.SubQuery> subQueryList
List ofIN
andEXISTS
nodes inside thisSELECT
statement (but not inside sub-queries).
-
agg
SqlToRelConverter.AggConverter agg
Workspace for building aggregates.
-
window
SqlWindow window
When converting window aggregate, we need to know if the window is guaranteed to be non-empty.
-
mapRootRelToFieldProjection
private final java.util.Map<RelNode,java.util.Map<java.lang.Integer,java.lang.Integer>> mapRootRelToFieldProjection
Project the groupby expressions out of the root of this sub-select. Sub-queries can reference group by expressions projected from the "right" to the sub-query.
-
columnMonotonicities
private final java.util.List<SqlMonotonicity> columnMonotonicities
-
systemFieldList
private final java.util.List<RelDataTypeField> systemFieldList
-
top
final boolean top
-
initializerExpressionFactory
private final InitializerExpressionFactory initializerExpressionFactory
-
-
Constructor Detail
-
Blackboard
protected Blackboard(SqlValidatorScope scope, java.util.Map<java.lang.String,RexNode> nameToNodeMap, boolean top)
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, saynameToNodeMap
- Map which translates the expression to map a given parameter into, if translating expressions; null otherwisetop
- Whether this is the root of the query
-
-
Method Detail
-
setPatternVarRef
public void setPatternVarRef(boolean isVarRef)
-
register
public RexNode register(RelNode rel, JoinRelType joinType)
-
register
public RexNode register(RelNode rel, JoinRelType joinType, java.util.List<RexNode> leftKeys)
Registers a relational expression.- Parameters:
rel
- Relational expressionjoinType
- Join typeleftKeys
- 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
-
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 expressionleaf
- 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-sub-query. In particular, relational expressions derived from JOIN operators are not leaves, but set expressions are.
-
setRoot
private void setRoot(java.util.List<RelNode> inputs, RelNode root, boolean hasSystemFields)
-
setDataset
public void setDataset(java.lang.String datasetName)
Notifies this Blackboard that the root just set usingsetRoot(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(java.util.List<RelNode> inputs)
-
lookupExp
Pair<RexNode,java.util.Map<java.lang.String,java.lang.Integer>> lookupExp(SqlQualified qualified)
Returns an expression with which to reference a from-list item.- Parameters:
qualified
- the alias of the from item- Returns:
- a
RexFieldAccess
orRexRangeRef
, 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 isoffset
.
-
getRootField
RelDataTypeField getRootField(RexInputRef inputRef)
-
flatten
public void flatten(java.util.List<RelNode> rels, int systemFieldCount, int[] start, java.util.List<Pair<RelNode,java.lang.Integer>> relOffsetList)
-
registerSubQuery
void registerSubQuery(SqlNode node, RelOptUtil.Logic logic)
-
getSubQuery
SqlToRelConverter.SubQuery getSubQuery(SqlNode expr)
-
retrieveCursors
com.google.common.collect.ImmutableList<RelNode> retrieveCursors()
-
convertExpression
public RexNode convertExpression(SqlNode expr)
Description copied from interface:SqlRexContext
- Specified by:
convertExpression
in interfaceInitializerContext
- Specified by:
convertExpression
in interfaceSqlRexContext
- Parameters:
expr
- Expression to translate- Returns:
- Converted expression
-
convertSortExpression
public RexFieldCollation convertSortExpression(SqlNode expr, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection)
Converts an item in an ORDER BY clause inside a window (OVER) clause, extracting DESC, NULLS LAST and NULLS FIRST flags first.
-
isConvertedSubq
private boolean isConvertedSubq(RexNode rex)
Determines whether a RexNode corresponds to a sub-query 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
-
getGroupCount
public int getGroupCount()
Description copied from interface:SqlRexContext
If the operator call occurs in an aggregate query, returns the number of columns in the GROUP BY clause. For example, for "SELECT count(*) FROM emp GROUP BY deptno, gender", returns 2. If the operator call occurs in window aggregate query, then returns 1 if the window is guaranteed to be non-empty, or 0 if the window might be empty.Returns 0 if the query is implicitly "GROUP BY ()" because of an aggregate expression. For example, "SELECT sum(sal) FROM emp".
Returns -1 if the query is not an aggregate query.
- Specified by:
getGroupCount
in interfaceSqlRexContext
- Returns:
- 0 if the query is implicitly GROUP BY (), -1 if the query is not and aggregate query
- See Also:
SqlOperatorBinding.getGroupCount()
-
getRexBuilder
public RexBuilder getRexBuilder()
Description copied from interface:SqlRexContext
Returns theRexBuilder
to use to createRexNode
objects.- Specified by:
getRexBuilder
in interfaceInitializerContext
- Specified by:
getRexBuilder
in interfaceSqlRexContext
-
getSubQueryExpr
public RexRangeRef getSubQueryExpr(SqlCall call)
Description copied from interface:SqlRexContext
Returns the expression used to access a given IN or EXISTSsub-query
.- Specified by:
getSubQueryExpr
in interfaceSqlRexContext
- 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 interfaceSqlRexContext
-
getInitializerExpressionFactory
public InitializerExpressionFactory getInitializerExpressionFactory()
Description copied from interface:SqlRexContext
Returns the factory which supplies default values for INSERT, UPDATE, and NEW.- Specified by:
getInitializerExpressionFactory
in interfaceSqlRexContext
-
getValidator
public SqlValidator getValidator()
Description copied from interface:SqlRexContext
Returns the validator.- Specified by:
getValidator
in interfaceSqlRexContext
-
convertLiteral
public RexNode convertLiteral(SqlLiteral literal)
Description copied from interface:SqlRexContext
Converts a literal.- Specified by:
convertLiteral
in interfaceSqlRexContext
-
convertInterval
public RexNode convertInterval(SqlIntervalQualifier intervalQualifier)
-
visit
public RexNode visit(SqlLiteral literal)
Description copied from interface:SqlVisitor
Visits a literal.- Specified by:
visit
in interfaceSqlVisitor<RexNode>
- Parameters:
literal
- Literal- See Also:
SqlLiteral.accept(SqlVisitor)
-
visit
public RexNode visit(SqlCall call)
Description copied from interface:SqlVisitor
Visits a call to aSqlOperator
.- Specified by:
visit
in interfaceSqlVisitor<RexNode>
- Parameters:
call
- Call- See Also:
SqlCall.accept(SqlVisitor)
-
visit
public RexNode visit(SqlNodeList nodeList)
Description copied from interface:SqlVisitor
Visits a list ofSqlNode
objects.- Specified by:
visit
in interfaceSqlVisitor<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 interfaceSqlVisitor<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 interfaceSqlVisitor<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 interfaceSqlVisitor<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 interfaceSqlVisitor<RexNode>
- Parameters:
intervalQualifier
- Interval qualifier- See Also:
SqlIntervalQualifier.accept(SqlVisitor)
-
getColumnMonotonicities
public java.util.List<SqlMonotonicity> getColumnMonotonicities()
-
-