public class SqlToRelConverter
extends java.lang.Object
SqlNode
objects) into a relational algebra
expression (consisting of RelNode
objects).
The public entry points are: convertQuery(org.apache.calcite.sql.SqlNode, boolean, boolean)
,
convertExpression(SqlNode)
.
Modifier and Type | Class and Description |
---|---|
protected class |
SqlToRelConverter.AggConverter
Converts expressions to aggregates.
|
private static class |
SqlToRelConverter.AggregateFinder
Visitor that collects all aggregate functions in a
SqlNode tree. |
protected class |
SqlToRelConverter.Blackboard
Workspace for translating an individual SELECT statement (or sub-SELECT).
|
static interface |
SqlToRelConverter.Config
Interface to define the configuration for a SqlToRelConverter.
|
static class |
SqlToRelConverter.ConfigBuilder
Builder for a
SqlToRelConverter.Config . |
private static class |
SqlToRelConverter.ConfigImpl
Implementation of
SqlToRelConverter.Config . |
private static class |
SqlToRelConverter.CorrelationUse
Use of a row as a correlating variable by a given relational
expression.
|
private static class |
SqlToRelConverter.DeferredLookup
Deferred lookup.
|
private class |
SqlToRelConverter.HistogramShuttle
Shuttle which walks over a tree of
RexNode s and applies 'over' to
all agg functions. |
private static class |
SqlToRelConverter.LookupContext
Context to find a relational expression to a field offset.
|
private class |
SqlToRelConverter.NoOpSubQueryConverter
A default implementation of SubQueryConverter that does no conversion.
|
private static class |
SqlToRelConverter.RexAccessShuttle
Shuttle that replace outer
RexInputRef with
RexFieldAccess , and adjust offset to
each inner RexInputRef in the lateral join
condition. |
private static class |
SqlToRelConverter.SubQuery
A sub-query, whether it needs to be translated using 2- or 3-valued
logic.
|
Modifier and Type | Field and Description |
---|---|
protected Prepare.CatalogReader |
catalogReader |
protected RelOptCluster |
cluster |
SqlToRelConverter.Config |
config |
private java.util.Deque<java.lang.String> |
datasetStack
Stack of names of datasets requested by the
TABLE(SAMPLE(<datasetName>, <query>)) construct. |
static int |
DEFAULT_IN_SUB_QUERY_THRESHOLD
Size of the smallest IN list that will be converted to a semijoin to a
static table.
|
static int |
DEFAULT_IN_SUBQUERY_THRESHOLD
Deprecated.
|
private java.util.List<SqlDynamicParam> |
dynamicParamSqlNodes |
private int |
explainParamCount |
private SqlNodeToRexConverter |
exprConverter |
protected java.util.List<RelNode> |
leaves |
private java.util.Map<SqlNode,RexNode> |
mapConvertedNonCorrSubqs
Mapping of non-correlated sub-queries that have been converted to their
equivalent constants.
|
private java.util.Map<CorrelationId,SqlToRelConverter.DeferredLookup> |
mapCorrelToDeferred
Fields used in name resolution for correlated sub-queries.
|
private SqlOperatorTable |
opTab |
private RelBuilder |
relBuilder |
protected RexBuilder |
rexBuilder |
protected static org.slf4j.Logger |
SQL2REL_LOGGER |
private SubQueryConverter |
subQueryConverter |
private static java.math.BigDecimal |
TWO |
protected RelDataTypeFactory |
typeFactory |
protected SqlValidator |
validator |
RelOptTable.ViewExpander |
viewExpander |
Constructor and Description |
---|
SqlToRelConverter(RelOptTable.ViewExpander viewExpander,
SqlValidator validator,
Prepare.CatalogReader catalogReader,
RelOptCluster cluster,
SqlRexConvertletTable convertletTable)
Deprecated.
|
SqlToRelConverter(RelOptTable.ViewExpander viewExpander,
SqlValidator validator,
Prepare.CatalogReader catalogReader,
RelOptCluster cluster,
SqlRexConvertletTable convertletTable,
SqlToRelConverter.Config config) |
SqlToRelConverter(RelOptTable.ViewExpander viewExpander,
SqlValidator validator,
Prepare.CatalogReader catalogReader,
RelOptPlanner planner,
RexBuilder rexBuilder,
SqlRexConvertletTable convertletTable)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
addConvertedNonCorrSubqs(java.util.Map<SqlNode,RexNode> alreadyConvertedNonCorrSubqs)
Adds to the current map of non-correlated converted sub-queries the
elements from another map that contains non-correlated sub-queries that
have been converted by another SqlToRelConverter.
|
protected RexNode |
adjustInputRef(SqlToRelConverter.Blackboard bb,
RexInputRef inputRef)
Adjusts the type of a reference to an input field to account for nulls
introduced by outer joins; and adjusts the offset to match the physical
implementation.
|
protected void |
afterTableFunction(SqlToRelConverter.Blackboard bb,
SqlCall call,
LogicalTableFunctionScan callRel) |
private boolean |
all(SqlCall call) |
private RexNode |
castNullLiteralIfNeeded(RexNode node,
RelDataType type) |
private void |
checkConvertedType(SqlNode query,
RelNode result) |
protected void |
collectInsertTargets(SqlInsert call,
RexNode sourceRef,
java.util.List<java.lang.String> targetColumnNames,
java.util.List<RexNode> columnExprs)
Given an INSERT statement, collects the list of names to be populated and
the expressions to put in them.
|
static SqlToRelConverter.ConfigBuilder |
configBuilder()
Creates a builder for a
SqlToRelConverter.Config . |
private static boolean |
containsInOperator(SqlNode node)
Returns whether a given node contains a
SqlInOperator . |
private static boolean |
containsNullLiteral(SqlNodeList valueList) |
protected void |
convertAgg(SqlToRelConverter.Blackboard bb,
SqlSelect select,
java.util.List<SqlNode> orderExprList)
Converts the SELECT, GROUP BY and HAVING clauses of an aggregate query.
|
protected void |
convertCollectionTable(SqlToRelConverter.Blackboard bb,
SqlCall call) |
protected RelNode |
convertColumnList(SqlInsert call,
RelNode source)
Creates a source for an INSERT statement.
|
private RelNode |
convertCursor(SqlToRelConverter.Blackboard bb,
SqlToRelConverter.SubQuery subQuery) |
private RelNode |
convertDelete(SqlDelete call) |
RexDynamicParam |
convertDynamicParam(SqlDynamicParam dynamicParam) |
private RelOptUtil.Exists |
convertExists(SqlNode seek,
RelOptUtil.SubQueryType subQueryType,
RelOptUtil.Logic logic,
boolean notIn,
RelDataType targetDataType)
Converts an EXISTS or IN predicate into a join.
|
RexNode |
convertExpression(SqlNode node)
|
RexNode |
convertExpression(SqlNode node,
java.util.Map<java.lang.String,RexNode> nameToNodeMap)
|
protected RexNode |
convertExtendedExpression(SqlNode node,
SqlToRelConverter.Blackboard bb)
Converts a non-standard expression.
|
protected void |
convertFrom(SqlToRelConverter.Blackboard bb,
SqlNode from)
Converts a FROM clause into a relational expression.
|
private RexNode |
convertIdentifier(SqlToRelConverter.Blackboard bb,
SqlIdentifier identifier)
Converts an identifier into an expression in a given scope.
|
private void |
convertIdentifier(SqlToRelConverter.Blackboard bb,
SqlIdentifier id,
SqlNodeList extendedColumns) |
protected RelNode |
convertInsert(SqlInsert call) |
private RexNode |
convertInToOr(SqlToRelConverter.Blackboard bb,
java.util.List<RexNode> leftKeys,
SqlNodeList valuesList,
SqlInOperator op)
Converts "x IN (1, 2, ...)" to "x=1 OR x=2 OR ...".
|
private RexNode |
convertJoinCondition(SqlToRelConverter.Blackboard bb,
SqlValidatorNamespace leftNamespace,
SqlValidatorNamespace rightNamespace,
SqlNode condition,
JoinConditionType conditionType,
RelNode leftRel,
RelNode rightRel) |
private static JoinRelType |
convertJoinType(JoinType joinType) |
private RexLiteral |
convertLiteralInValuesList(SqlNode sqlNode,
SqlToRelConverter.Blackboard bb,
RelDataType rowType,
int iField) |
protected void |
convertMatchRecognize(SqlToRelConverter.Blackboard bb,
SqlCall call) |
private RelNode |
convertMerge(SqlMerge call) |
private RelNode |
convertMultisets(java.util.List<SqlNode> operands,
SqlToRelConverter.Blackboard bb) |
private boolean |
convertNonCorrelatedSubQuery(SqlToRelConverter.SubQuery subQuery,
SqlToRelConverter.Blackboard bb,
RelNode converted,
boolean isExists)
Determines if a sub-query is non-correlated and if so, converts it to a
constant.
|
protected void |
convertOrder(SqlSelect select,
SqlToRelConverter.Blackboard bb,
RelCollation collation,
java.util.List<SqlNode> orderExprList,
SqlNode offset,
SqlNode fetch)
Converts a query's ORDER BY clause, if any.
|
protected RelFieldCollation |
convertOrderItem(SqlSelect select,
SqlNode orderItem,
java.util.List<SqlNode> extraExprs,
RelFieldCollation.Direction direction,
RelFieldCollation.NullDirection nullDirection) |
private RexNode |
convertOver(SqlToRelConverter.Blackboard bb,
SqlNode node) |
RelRoot |
convertQuery(SqlNode query,
boolean needsValidation,
boolean top)
Converts an unvalidated query's parse tree into a relational expression.
|
private RelNode |
convertQueryOrInList(SqlToRelConverter.Blackboard bb,
SqlNode seek,
RelDataType targetRowType) |
protected RelRoot |
convertQueryRecursive(SqlNode query,
boolean top,
RelDataType targetRowType)
Recursively converts a query to a relational expression.
|
private RelNode |
convertRowConstructor(SqlToRelConverter.Blackboard bb,
SqlCall rowConstructor)
Converts a row constructor into a relational expression.
|
private RelNode |
convertRowValues(SqlToRelConverter.Blackboard bb,
SqlNode rowList,
java.util.Collection<SqlNode> rows,
boolean allowLiteralsOnly,
RelDataType targetRowType) |
RelNode |
convertSelect(SqlSelect select,
boolean top)
Converts a SELECT statement's parse tree into a relational expression.
|
protected void |
convertSelectImpl(SqlToRelConverter.Blackboard bb,
SqlSelect select)
Implementation of
convertSelect(SqlSelect, boolean) ;
derived class may override. |
private void |
convertSelectList(SqlToRelConverter.Blackboard bb,
SqlSelect select,
java.util.List<SqlNode> orderList) |
protected RelNode |
convertSetOp(SqlCall call)
Converts a set operation (UNION, INTERSECT, MINUS) into relational
expressions.
|
RelNode |
convertToSingleValueSubq(SqlNode query,
RelNode plan)
Converts the RelNode tree for a select statement to a select that
produces a single value.
|
private RelNode |
convertUpdate(SqlUpdate call) |
private RexNode |
convertUsing(SqlValidatorNamespace leftNamespace,
SqlValidatorNamespace rightNamespace,
java.util.List<java.lang.String> nameList)
Returns an expression for matching columns of a USING clause or inferred
from NATURAL JOIN.
|
RelNode |
convertValues(SqlCall values,
RelDataType targetRowType)
Converts a SELECT statement's parse tree into a relational expression.
|
private void |
convertValuesImpl(SqlToRelConverter.Blackboard bb,
SqlCall values,
RelDataType targetRowType)
Converts a values clause (as in "INSERT INTO T(x,y) VALUES (1,2)") into a
relational expression.
|
private void |
convertWhere(SqlToRelConverter.Blackboard bb,
SqlNode where)
Converts a WHERE clause.
|
RelRoot |
convertWith(SqlWith with,
boolean top)
Converts a WITH sub-query into a relational expression.
|
protected void |
createAggImpl(SqlToRelConverter.Blackboard bb,
SqlToRelConverter.AggConverter aggConverter,
SqlNodeList selectList,
SqlNodeList groupList,
SqlNode having,
java.util.List<SqlNode> orderExprList) |
protected RelNode |
createAggregate(SqlToRelConverter.Blackboard bb,
ImmutableBitSet groupSet,
com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets,
java.util.List<AggregateCall> aggCalls)
Creates an Aggregate.
|
protected SqlToRelConverter.Blackboard |
createBlackboard(SqlValidatorScope scope,
java.util.Map<java.lang.String,RexNode> nameToNodeMap,
boolean top)
Factory method for creating translation workspace.
|
private SqlToRelConverter.Blackboard |
createInsertBlackboard(RelOptTable targetTable,
RexNode sourceRef,
java.util.List<java.lang.String> targetColumnNames)
Creates a blackboard for translating the expressions of generated columns
in an INSERT statement.
|
protected RelNode |
createJoin(SqlToRelConverter.Blackboard bb,
RelNode leftRel,
RelNode rightRel,
RexNode joinCond,
JoinRelType joinType) |
private RelNode |
createModify(RelOptTable targetTable,
RelNode source)
Creates a relational expression to modify a table or modifiable view.
|
private RelNode |
createSource(RelOptTable targetTable,
RelNode source,
ModifiableView modifiableView,
RelDataType delegateRowType)
Wraps a relational expression in the projects and filters implied by
a
ModifiableView . |
private RelOptTable.ToRelContext |
createToRelContext() |
RelNode |
decorrelate(SqlNode query,
RelNode rootRel)
If sub-query is correlated and decorrelation is enabled, performs
decorrelation.
|
protected RelNode |
decorrelateQuery(RelNode rootRel) |
private java.lang.String |
deriveAlias(SqlNode node,
java.util.Collection<java.lang.String> aliases,
int ordinal) |
private static boolean |
desc(RelFieldCollation.Direction direction) |
private void |
distinctify(SqlToRelConverter.Blackboard bb,
boolean checkForDupExprs)
Having translated 'SELECT ...
|
protected boolean |
enableDecorrelation()
Deprecated.
|
private RexNode |
ensureSqlType(RelDataType type,
RexNode node)
Ensures that an expression has a given
SqlTypeName , applying a
cast if necessary. |
protected void |
extraSelectItems(SqlToRelConverter.Blackboard bb,
SqlSelect select,
java.util.List<RexNode> exprList,
java.util.List<java.lang.String> nameList,
java.util.Collection<java.lang.String> aliasList,
java.util.List<SqlMonotonicity> columnMonotonicityList)
Adds extra select items.
|
private void |
findSubQueries(SqlToRelConverter.Blackboard bb,
SqlNode node,
RelOptUtil.Logic logic,
boolean registerOnlyScalarSubQueries)
Builds a list of all
IN or EXISTS operators
inside SQL parse tree. |
RelNode |
flattenTypes(RelNode rootRel,
boolean restructure) |
protected void |
gatherOrderExprs(SqlToRelConverter.Blackboard bb,
SqlSelect select,
SqlNodeList orderList,
java.util.List<SqlNode> extraOrderExprs,
java.util.List<RelFieldCollation> collationList)
Creates a list of collations required to implement the ORDER BY clause,
if there is one.
|
RelOptCluster |
getCluster() |
private java.util.Set<RelColumnMapping> |
getColumnMappings(SqlOperator op) |
private SqlToRelConverter.CorrelationUse |
getCorrelationUse(SqlToRelConverter.Blackboard bb,
RelNode r0) |
int |
getDynamicParamCount()
Returns the number of dynamic parameters encountered during translation;
this must only be called after
convertQuery(org.apache.calcite.sql.SqlNode, boolean, boolean) . |
int |
getDynamicParamCountInExplain(boolean increment)
Returns the current count of the number of dynamic parameters in an
EXPLAIN PLAN statement.
|
RelDataType |
getDynamicParamType(int index)
Returns the type inferred for a dynamic parameter.
|
private InitializerExpressionFactory |
getInitializerFactory(SqlValidatorTable validatorTable) |
protected int |
getInSubqueryThreshold()
Deprecated.
|
java.util.Map<SqlNode,RexNode> |
getMapConvertedNonCorrSubqs() |
RexBuilder |
getRexBuilder()
Returns the row-expression builder.
|
protected java.util.List<RelDataTypeField> |
getSystemFields()
Returns a list of fields to be prefixed to each relational expression.
|
protected RelOptTable |
getTargetTable(SqlNode call) |
static boolean |
isOrdered(SqlNode query) |
private boolean |
isRowConstructor(SqlNode node) |
private static boolean |
isStream(SqlNode query) |
private boolean |
isSubQueryNonCorrelated(RelNode subq,
SqlToRelConverter.Blackboard bb)
Determines whether a sub-query is non-correlated.
|
boolean |
isTrimUnusedFields()
Deprecated.
|
private SqlQuantifyOperator |
negate(SqlQuantifyOperator operator) |
protected RelFieldTrimmer |
newFieldTrimmer()
Creates a RelFieldTrimmer.
|
private static SqlNode |
pushDownNotForIn(SqlValidatorScope scope,
SqlNode sqlNode)
Push down all the NOT logical operators into any IN/NOT IN operators.
|
private static SqlNode |
reg(SqlValidatorScope scope,
SqlNode e)
Registers with the validator a
SqlNode that has been created
during the Sql-to-Rel process. |
private void |
replaceSubQueries(SqlToRelConverter.Blackboard bb,
SqlNode expr,
RelOptUtil.Logic logic) |
private RelCollation |
requiredCollation(RelNode r) |
void |
setDynamicParamCountInExplain(int explainParamCount)
Sets the number of dynamic parameters in the current EXPLAIN PLAN
statement.
|
void |
setSubQueryConverter(SubQueryConverter converter)
Sets a new SubQueryConverter.
|
private void |
snapshotTemporalTable(SqlToRelConverter.Blackboard bb,
SqlCall call) |
private void |
substituteSubQuery(SqlToRelConverter.Blackboard bb,
SqlToRelConverter.SubQuery subQuery) |
RelNode |
toRel(RelOptTable table) |
private RexNode |
translateIn(RelOptUtil.Logic logic,
RelNode root,
RexNode rex) |
RelNode |
trimUnusedFields(boolean ordered,
RelNode rootRel)
Walks over a tree of relational expressions, replacing each
RelNode with a 'slimmed down' relational expression that projects
only the fields required by its consumer. |
private static <T> T |
unwrap(java.lang.Object o,
java.lang.Class<T> clazz) |
protected static final org.slf4j.Logger SQL2REL_LOGGER
private static final java.math.BigDecimal TWO
public static final int DEFAULT_IN_SUB_QUERY_THRESHOLD
@Deprecated public static final int DEFAULT_IN_SUBQUERY_THRESHOLD
protected final SqlValidator validator
protected final RexBuilder rexBuilder
protected final Prepare.CatalogReader catalogReader
protected final RelOptCluster cluster
private SubQueryConverter subQueryConverter
protected final java.util.List<RelNode> leaves
private final java.util.List<SqlDynamicParam> dynamicParamSqlNodes
private final SqlOperatorTable opTab
protected final RelDataTypeFactory typeFactory
private final SqlNodeToRexConverter exprConverter
private int explainParamCount
public final SqlToRelConverter.Config config
private final RelBuilder relBuilder
private final java.util.Map<CorrelationId,SqlToRelConverter.DeferredLookup> mapCorrelToDeferred
private final java.util.Deque<java.lang.String> datasetStack
TABLE(SAMPLE(<datasetName>, <query>))
construct.private final java.util.Map<SqlNode,RexNode> mapConvertedNonCorrSubqs
public final RelOptTable.ViewExpander viewExpander
@Deprecated public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator validator, Prepare.CatalogReader catalogReader, RelOptPlanner planner, RexBuilder rexBuilder, SqlRexConvertletTable convertletTable)
viewExpander
- Preparing statementvalidator
- ValidatorcatalogReader
- Schemaplanner
- PlannerrexBuilder
- Rex builderconvertletTable
- Expression converter@Deprecated public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator validator, Prepare.CatalogReader catalogReader, RelOptCluster cluster, SqlRexConvertletTable convertletTable)
public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator validator, Prepare.CatalogReader catalogReader, RelOptCluster cluster, SqlRexConvertletTable convertletTable, SqlToRelConverter.Config config)
public RelOptCluster getCluster()
public RexBuilder getRexBuilder()
public int getDynamicParamCount()
convertQuery(org.apache.calcite.sql.SqlNode, boolean, boolean)
.public RelDataType getDynamicParamType(int index)
index
- 0-based index of dynamic parameterpublic int getDynamicParamCountInExplain(boolean increment)
increment
- if true, increment the countpublic java.util.Map<SqlNode,RexNode> getMapConvertedNonCorrSubqs()
public void addConvertedNonCorrSubqs(java.util.Map<SqlNode,RexNode> alreadyConvertedNonCorrSubqs)
alreadyConvertedNonCorrSubqs
- the other mappublic void setSubQueryConverter(SubQueryConverter converter)
converter
- new SubQueryConverterpublic void setDynamicParamCountInExplain(int explainParamCount)
explainParamCount
- number of dynamic parameters in the statementpublic RelNode decorrelate(SqlNode query, RelNode rootRel)
query
- QueryrootRel
- Root relational expressionpublic RelNode trimUnusedFields(boolean ordered, RelNode rootRel)
RelNode
with a 'slimmed down' relational expression that projects
only the fields required by its consumer.
This may make things easier for the optimizer, by removing crud that
would expand the search space, but is difficult for the optimizer itself
to do it, because optimizer rules must preserve the number and type of
fields. Hence, this transform that operates on the entire tree, similar
to the type-flattening transform
.
Currently this functionality is disabled in farrago/luciddb; the default implementation of this method does nothing.
ordered
- Whether the relational expression must produce results in
a particular order (typically because it has an ORDER BY at top level)rootRel
- Relational expression that is at the root of the treeprotected RelFieldTrimmer newFieldTrimmer()
public RelRoot convertQuery(SqlNode query, boolean needsValidation, boolean top)
query
- Query to convertneedsValidation
- Whether to validate the query before converting;
false
if the query has already been
validated.top
- Whether the query is top-level, say if its result
will become a JDBC result set; false
if
the query will be part of a view.private static boolean isStream(SqlNode query)
public static boolean isOrdered(SqlNode query)
private RelCollation requiredCollation(RelNode r)
public RelNode convertSelect(SqlSelect select, boolean top)
protected SqlToRelConverter.Blackboard createBlackboard(SqlValidatorScope scope, java.util.Map<java.lang.String,RexNode> nameToNodeMap, boolean top)
protected void convertSelectImpl(SqlToRelConverter.Blackboard bb, SqlSelect select)
convertSelect(SqlSelect, boolean)
;
derived class may override.private void distinctify(SqlToRelConverter.Blackboard bb, boolean checkForDupExprs)
If the SELECT clause contains duplicate expressions, adds
LogicalProject
s so that we are
grouping on the minimal set of keys. The performance gain isn't huge, but
it is difficult to detect these duplicate expressions later.
bb
- BlackboardcheckForDupExprs
- Check for duplicate expressionsprotected void convertOrder(SqlSelect select, SqlToRelConverter.Blackboard bb, RelCollation collation, java.util.List<SqlNode> orderExprList, SqlNode offset, SqlNode fetch)
Ignores the ORDER BY clause if the query is not top-level and FETCH or OFFSET are not present.
select
- Querybb
- Blackboardcollation
- Collation listorderExprList
- Method populates this list with orderBy expressions
not present in selectListoffset
- Expression for number of rows to discard before
returning first rowfetch
- Expression for number of rows to fetchprivate static boolean containsInOperator(SqlNode node)
SqlInOperator
.node
- a RexNode treeprivate static SqlNode pushDownNotForIn(SqlValidatorScope scope, SqlNode sqlNode)
scope
- Scope where sqlNode
occurssqlNode
- the root node from which to look for NOT operatorsprivate static SqlNode reg(SqlValidatorScope scope, SqlNode e)
SqlNode
that has been created
during the Sql-to-Rel process.private void convertWhere(SqlToRelConverter.Blackboard bb, SqlNode where)
bb
- Blackboardwhere
- WHERE clause, may be nullprivate void replaceSubQueries(SqlToRelConverter.Blackboard bb, SqlNode expr, RelOptUtil.Logic logic)
private void substituteSubQuery(SqlToRelConverter.Blackboard bb, SqlToRelConverter.SubQuery subQuery)
private RexNode translateIn(RelOptUtil.Logic logic, RelNode root, RexNode rex)
private static boolean containsNullLiteral(SqlNodeList valueList)
private boolean convertNonCorrelatedSubQuery(SqlToRelConverter.SubQuery subQuery, SqlToRelConverter.Blackboard bb, RelNode converted, boolean isExists)
subQuery
- the call that references the sub-querybb
- blackboard used to convert the sub-queryconverted
- RelNode tree corresponding to the sub-queryisExists
- true if the sub-query is part of an EXISTS expressionpublic RelNode convertToSingleValueSubq(SqlNode query, RelNode plan)
query
- the queryplan
- the original RelNode tree corresponding to the statementprivate RexNode convertInToOr(SqlToRelConverter.Blackboard bb, java.util.List<RexNode> leftKeys, SqlNodeList valuesList, SqlInOperator op)
leftKeys
- LHSvaluesList
- RHSop
- The operator (IN, NOT IN, > SOME, ...)private RexNode ensureSqlType(RelDataType type, RexNode node)
SqlTypeName
, applying a
cast if necessary. If the expression already has the right type family,
returns the expression unchanged.@Deprecated protected int getInSubqueryThreshold()
convertInToOr(org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard, java.util.List<org.apache.calcite.rex.RexNode>, org.apache.calcite.sql.SqlNodeList, org.apache.calcite.sql.fun.SqlInOperator)
is used.
Lists of this size or greater will instead be converted to use a join
against an inline table
(LogicalValues
) rather than a
predicate. A threshold of 0 forces usage of an inline table in all cases; a
threshold of Integer.MAX_VALUE forces usage of OR in all casesDEFAULT_IN_SUB_QUERY_THRESHOLD
private RelOptUtil.Exists convertExists(SqlNode seek, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn, RelDataType targetDataType)
seek
- A query, for example 'select * from emp' or
'values (1,2,3)' or '('Foo', 34)'.subQueryType
- Whether sub-query is IN, EXISTS or scalarlogic
- Whether the answer needs to be in full 3-valued logic (TRUE,
FALSE, UNKNOWN) will be required, or whether we can accept an
approximation (say representing UNKNOWN as FALSE)notIn
- Whether the operation is NOT INprivate RelNode convertQueryOrInList(SqlToRelConverter.Blackboard bb, SqlNode seek, RelDataType targetRowType)
private RelNode convertRowValues(SqlToRelConverter.Blackboard bb, SqlNode rowList, java.util.Collection<SqlNode> rows, boolean allowLiteralsOnly, RelDataType targetRowType)
private RexLiteral convertLiteralInValuesList(SqlNode sqlNode, SqlToRelConverter.Blackboard bb, RelDataType rowType, int iField)
private boolean isRowConstructor(SqlNode node)
private void findSubQueries(SqlToRelConverter.Blackboard bb, SqlNode node, RelOptUtil.Logic logic, boolean registerOnlyScalarSubQueries)
IN
or EXISTS
operators
inside SQL parse tree. Does not traverse inside queries.bb
- blackboardnode
- the SQL parse treelogic
- Whether the answer needs to be in full 3-valued logic (TRUE,
FALSE, UNKNOWN) will be required, or whether we can accept
an approximation (say representing UNKNOWN as FALSE)registerOnlyScalarSubQueries
- if set to true and the parse tree
corresponds to a variation of a select
node, only register it if it's a scalar
sub-querypublic RexNode convertExpression(SqlNode node)
node
- Expression to translatepublic RexNode convertExpression(SqlNode node, java.util.Map<java.lang.String,RexNode> nameToNodeMap)
SqlNode
to RexNode
format,
mapping identifier references to predefined expressions.node
- Expression to translatenameToNodeMap
- map from String to RexNode
; when an
SqlIdentifier
is encountered, it is used as a
key and translated to the corresponding value from
this mapprotected RexNode convertExtendedExpression(SqlNode node, SqlToRelConverter.Blackboard bb)
This method is an extension-point that derived classes can override. If this method returns a null result, the normal expression translation process will proceed. The default implementation always returns null.
node
- Expressionbb
- Blackboardprivate RexNode convertOver(SqlToRelConverter.Blackboard bb, SqlNode node)
protected void convertFrom(SqlToRelConverter.Blackboard bb, SqlNode from)
bb
- Scope within which to resolve identifiersfrom
- FROM clause of a query. Examples include:
protected void convertMatchRecognize(SqlToRelConverter.Blackboard bb, SqlCall call)
private void convertIdentifier(SqlToRelConverter.Blackboard bb, SqlIdentifier id, SqlNodeList extendedColumns)
protected void convertCollectionTable(SqlToRelConverter.Blackboard bb, SqlCall call)
protected void afterTableFunction(SqlToRelConverter.Blackboard bb, SqlCall call, LogicalTableFunctionScan callRel)
private void snapshotTemporalTable(SqlToRelConverter.Blackboard bb, SqlCall call)
private java.util.Set<RelColumnMapping> getColumnMappings(SqlOperator op)
protected RelNode createJoin(SqlToRelConverter.Blackboard bb, RelNode leftRel, RelNode rightRel, RexNode joinCond, JoinRelType joinType)
private SqlToRelConverter.CorrelationUse getCorrelationUse(SqlToRelConverter.Blackboard bb, RelNode r0)
private boolean isSubQueryNonCorrelated(RelNode subq, SqlToRelConverter.Blackboard bb)
subq
- the sub-querybb
- blackboard used while converting the sub-query, i.e., the
blackboard of the parent query of this sub-queryprotected java.util.List<RelDataTypeField> getSystemFields()
private RexNode convertJoinCondition(SqlToRelConverter.Blackboard bb, SqlValidatorNamespace leftNamespace, SqlValidatorNamespace rightNamespace, SqlNode condition, JoinConditionType conditionType, RelNode leftRel, RelNode rightRel)
@Nonnull private RexNode convertUsing(SqlValidatorNamespace leftNamespace, SqlValidatorNamespace rightNamespace, java.util.List<java.lang.String> nameList)
leftNamespace
- Namespace of left input to joinrightNamespace
- Namespace of right input to joinnameList
- List of column names to join onprivate static JoinRelType convertJoinType(JoinType joinType)
protected void convertAgg(SqlToRelConverter.Blackboard bb, SqlSelect select, java.util.List<SqlNode> orderExprList)
This method extracts SELECT, GROUP BY and HAVING clauses, and creates
an SqlToRelConverter.AggConverter
, then delegates to createAggImpl(org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard, org.apache.calcite.sql2rel.SqlToRelConverter.AggConverter, org.apache.calcite.sql.SqlNodeList, org.apache.calcite.sql.SqlNodeList, org.apache.calcite.sql.SqlNode, java.util.List<org.apache.calcite.sql.SqlNode>)
.
Derived class may override this method to change any of those clauses or
specify a different SqlToRelConverter.AggConverter
.
bb
- Scope within which to resolve identifiersselect
- QueryorderExprList
- Additional expressions needed to implement ORDER BYprotected final void createAggImpl(SqlToRelConverter.Blackboard bb, SqlToRelConverter.AggConverter aggConverter, SqlNodeList selectList, SqlNodeList groupList, SqlNode having, java.util.List<SqlNode> orderExprList)
protected RelNode createAggregate(SqlToRelConverter.Blackboard bb, ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets, java.util.List<AggregateCall> aggCalls)
In case the aggregate rel changes the order in which it projects
fields, the groupExprProjection
parameter is provided, and
the implementation of this method may modify it.
The sortedCount
parameter is the number of expressions
known to be monotonic. These expressions must be on the leading edge of
the grouping keys. The default implementation of this method ignores this
parameter.
bb
- BlackboardgroupSet
- Bit set of ordinals of grouping columnsgroupSets
- Grouping setsaggCalls
- Array of calls to aggregate functionspublic RexDynamicParam convertDynamicParam(SqlDynamicParam dynamicParam)
protected void gatherOrderExprs(SqlToRelConverter.Blackboard bb, SqlSelect select, SqlNodeList orderList, java.util.List<SqlNode> extraOrderExprs, java.util.List<RelFieldCollation> collationList)
extraOrderExprs
with any sort
expressions which are not in the select clause.bb
- Scope within which to resolve identifiersselect
- Select clause. Never null, because we invent a
dummy SELECT if ORDER BY is applied to a set
operation (UNION etc.)orderList
- Order by clause, may be nullextraOrderExprs
- Sort expressions which are not in the select
clause (output)collationList
- List of collations (output)protected RelFieldCollation convertOrderItem(SqlSelect select, SqlNode orderItem, java.util.List<SqlNode> extraExprs, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection)
private static boolean desc(RelFieldCollation.Direction direction)
@Deprecated protected boolean enableDecorrelation()
@Deprecated public boolean isTrimUnusedFields()
protected RelRoot convertQueryRecursive(SqlNode query, boolean top, RelDataType targetRowType)
query
- Querytop
- Whether this query is the top-level query of the
statementtargetRowType
- Target row type, or nullprotected RelNode convertSetOp(SqlCall call)
call
- Call to set operatorprivate boolean all(SqlCall call)
private RelNode createModify(RelOptTable targetTable, RelNode source)
private RelNode createSource(RelOptTable targetTable, RelNode source, ModifiableView modifiableView, RelDataType delegateRowType)
ModifiableView
.
The input relational expression is suitable for inserting into the view, and the returned relational expression is suitable for inserting into its delegate table.
In principle, the delegate table of a view might be another modifiable view, and if so, the process can be repeated.
private RelOptTable.ToRelContext createToRelContext()
public RelNode toRel(RelOptTable table)
protected RelOptTable getTargetTable(SqlNode call)
protected RelNode convertColumnList(SqlInsert call, RelNode source)
If the column list is not specified, source expressions match target columns in order.
If the column list is specified, Source expressions are mapped to target columns by name via targetColumnList, and may not cover the entire target table. So, we'll make up a full row, using a combination of default values and the source expressions provided.
call
- Insert expressionsource
- Source relational expressionprivate SqlToRelConverter.Blackboard createInsertBlackboard(RelOptTable targetTable, RexNode sourceRef, java.util.List<java.lang.String> targetColumnNames)
private InitializerExpressionFactory getInitializerFactory(SqlValidatorTable validatorTable)
private static <T> T unwrap(java.lang.Object o, java.lang.Class<T> clazz)
private RexNode castNullLiteralIfNeeded(RexNode node, RelDataType type)
protected void collectInsertTargets(SqlInsert call, RexNode sourceRef, java.util.List<java.lang.String> targetColumnNames, java.util.List<RexNode> columnExprs)
call
- Insert statementsourceRef
- Expression representing a row from the source
relational expressiontargetColumnNames
- List of target column names, to be populatedcolumnExprs
- List of expressions, to be populatedprivate RexNode convertIdentifier(SqlToRelConverter.Blackboard bb, SqlIdentifier identifier)
protected RexNode adjustInputRef(SqlToRelConverter.Blackboard bb, RexInputRef inputRef)
bb
- BlackboardinputRef
- Input refprivate RelNode convertRowConstructor(SqlToRelConverter.Blackboard bb, SqlCall rowConstructor)
bb
- BlackboardrowConstructor
- Row constructor expressionprivate RelNode convertCursor(SqlToRelConverter.Blackboard bb, SqlToRelConverter.SubQuery subQuery)
private RelNode convertMultisets(java.util.List<SqlNode> operands, SqlToRelConverter.Blackboard bb)
private void convertSelectList(SqlToRelConverter.Blackboard bb, SqlSelect select, java.util.List<SqlNode> orderList)
protected void extraSelectItems(SqlToRelConverter.Blackboard bb, SqlSelect select, java.util.List<RexNode> exprList, java.util.List<java.lang.String> nameList, java.util.Collection<java.lang.String> aliasList, java.util.List<SqlMonotonicity> columnMonotonicityList)
bb
- Blackboardselect
- Select statement being translatedexprList
- List of expressions in select clausenameList
- List of names, one per columnaliasList
- Collection of aliases that have been used
alreadycolumnMonotonicityList
- List of monotonicity, one per columnprivate java.lang.String deriveAlias(SqlNode node, java.util.Collection<java.lang.String> aliases, int ordinal)
public RelRoot convertWith(SqlWith with, boolean top)
public RelNode convertValues(SqlCall values, RelDataType targetRowType)
private void convertValuesImpl(SqlToRelConverter.Blackboard bb, SqlCall values, RelDataType targetRowType)
bb
- Blackboardvalues
- Call to SQL VALUES operatortargetRowType
- Target row typeprivate SqlQuantifyOperator negate(SqlQuantifyOperator operator)
public static SqlToRelConverter.ConfigBuilder configBuilder()
SqlToRelConverter.Config
.Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.