Class SqlToRelConverter
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).
FLINK modifications are at lines
- Added in FLINK-29081, FLINK-28682, FLINK-33395: Lines 661 ~ 678
- Added in Flink-24024: Lines 1457 ~ 1461
- Added in Flink-24024: Lines 1478 ~ 1513
- Added in FLINK-28682: Lines 2346 ~ 2363
- Added in FLINK-28682: Lines 2400 ~ 2428
- Added in FLINK-32474: Lines 2480 ~ 2482
- Added in FLINK-32474: Lines 2486 ~ 2488
- Added in FLINK-32474: Lines 2499 ~ 2501
- Added in FLINK-32474: Lines 2906 ~ 2918
- Added in FLINK-32474: Lines 3019 ~ 3053
- Added in FLINK-34312: Lines 5804 ~ 5813
- Added in FLINK-34057, FLINK-34058, FLINK-34312: Lines 6263 ~ 6279
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classConverts expressions to aggregates.protected classWorkspace for translating an individual SELECT statement (or sub-SELECT).static interfaceInterface to define the configuration for a SqlToRelConverter.static classVisitor that looks for an SqlIdentifier inside a tree ofSqlNodeobjects and returnBoolean.TRUEwhen it finds one. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.calcite.prepare.Prepare.CatalogReaderprotected final org.apache.calcite.plan.RelOptClusterfinal SqlToRelConverter.Configstatic final SqlToRelConverter.ConfigDefault configuration.static final intSize of the smallest IN list that will be converted to a semijoin to a static table.static final intDeprecated.protected final org.apache.calcite.rex.RexBuilderprotected static final org.slf4j.Loggerprotected final org.apache.calcite.rel.type.RelDataTypeFactoryfinal @Nullable org.apache.calcite.sql.validate.SqlValidatorfinal org.apache.calcite.plan.RelOptTable.ViewExpander -
Constructor Summary
ConstructorsConstructorDescriptionSqlToRelConverter(org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander, @Nullable org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.sql2rel.SqlRexConvertletTable convertletTable, SqlToRelConverter.Config config) SqlToRelConverter(org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander, org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.sql2rel.SqlRexConvertletTable convertletTable) Deprecated.SqlToRelConverter(org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander, org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.plan.RelOptPlanner planner, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.sql2rel.SqlRexConvertletTable convertletTable) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConvertedNonCorrSubqs(Map<org.apache.calcite.sql.SqlNode, org.apache.calcite.rex.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 org.apache.calcite.rex.RexNodeadjustInputRef(SqlToRelConverter.Blackboard bb, org.apache.calcite.rex.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 voidafterTableFunction(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlCall call, org.apache.calcite.rel.logical.LogicalTableFunctionScan callRel) protected voidcollectInsertTargets(org.apache.calcite.sql.SqlInsert call, org.apache.calcite.rex.RexNode sourceRef, List<String> targetColumnNames, List<org.apache.calcite.rex.RexNode> columnExprs) Given an INSERT statement, collects the list of names to be populated and the expressions to put in them.static SqlToRelConverter.Configconfig()Returns a defaultSqlToRelConverter.Config.voidTo tell this converter that this SqlNode tree contains query hints and then a query block alias will be attached to the root node of the query block.protected voidconvertAgg(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select, List<org.apache.calcite.sql.SqlNode> orderExprList) Converts the SELECT, GROUP BY and HAVING clauses of an aggregate query.protected voidconvertCollectionTable(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlCall call) protected org.apache.calcite.rel.RelNodeconvertColumnList(org.apache.calcite.sql.SqlInsert call, org.apache.calcite.rel.RelNode source) Creates a source for an INSERT statement.org.apache.calcite.rex.RexDynamicParamconvertDynamicParam(org.apache.calcite.sql.SqlDynamicParam dynamicParam) org.apache.calcite.rex.RexNodeconvertExpression(org.apache.calcite.sql.SqlNode node) Converts an expression fromSqlNodetoRexNodeformat.org.apache.calcite.rex.RexNodeconvertExpression(org.apache.calcite.sql.SqlNode node, Map<String, org.apache.calcite.rex.RexNode> nameToNodeMap) Converts an expression fromSqlNodetoRexNodeformat, mapping identifier references to predefined expressions.protected @Nullable org.apache.calcite.rex.RexNodeconvertExtendedExpression(org.apache.calcite.sql.SqlNode node, SqlToRelConverter.Blackboard bb) Converts a non-standard expression.protected voidconvertFrom(SqlToRelConverter.Blackboard bb, @Nullable org.apache.calcite.sql.SqlNode from) protected voidconvertFrom(SqlToRelConverter.Blackboard bb, @Nullable org.apache.calcite.sql.SqlNode from, @Nullable List<String> fieldNames) Converts a FROM clause into a relational expression.protected org.apache.calcite.rel.RelNodeconvertInsert(org.apache.calcite.sql.SqlInsert call) protected voidconvertMatchRecognize(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlMatchRecognize matchRecognize) protected voidconvertOrder(org.apache.calcite.sql.SqlSelect select, SqlToRelConverter.Blackboard bb, org.apache.calcite.rel.RelCollation collation, List<org.apache.calcite.sql.SqlNode> orderExprList, @Nullable org.apache.calcite.sql.SqlNode offset, @Nullable org.apache.calcite.sql.SqlNode fetch) Converts a query's ORDER BY clause, if any.protected org.apache.calcite.rel.RelFieldCollationconvertOrderItem(org.apache.calcite.sql.SqlSelect select, org.apache.calcite.sql.SqlNode orderItem, List<org.apache.calcite.sql.SqlNode> extraExprs, org.apache.calcite.rel.RelFieldCollation.Direction direction, org.apache.calcite.rel.RelFieldCollation.NullDirection nullDirection) protected voidconvertPivot(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlPivot pivot) org.apache.calcite.rel.RelRootconvertQuery(org.apache.calcite.sql.SqlNode query, boolean needsValidation, boolean top) Converts an unvalidated query's parse tree into a relational expression.protected org.apache.calcite.rel.RelRootconvertQueryRecursive(org.apache.calcite.sql.SqlNode query, boolean top, @Nullable org.apache.calcite.rel.type.RelDataType targetRowType) Recursively converts a query to a relational expression.org.apache.calcite.rel.RelNodeconvertSelect(org.apache.calcite.sql.SqlSelect select, boolean top) Converts a SELECT statement's parse tree into a relational expression.protected voidconvertSelectImpl(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select) Implementation ofconvertSelect(SqlSelect, boolean); derived class may override.protected org.apache.calcite.rel.RelNodeconvertSetOp(org.apache.calcite.sql.SqlCall call) Converts a set operation (UNION, INTERSECT, MINUS) into relational expressions.org.apache.calcite.rel.RelNodeconvertToSingleValueSubq(org.apache.calcite.sql.SqlNode query, org.apache.calcite.rel.RelNode plan) Converts the RelNode tree for a select statement to a select that produces a single value.protected voidconvertUnpivot(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlUnpivot unpivot) org.apache.calcite.rel.RelNodeconvertValues(org.apache.calcite.sql.SqlCall values, @Nullable org.apache.calcite.rel.type.RelDataType targetRowType) Converts a SELECT statement's parse tree into a relational expression.org.apache.calcite.rel.RelRootconvertWith(org.apache.calcite.sql.SqlWith with, boolean top) Converts a WITH sub-query into a relational expression.protected final voidcreateAggImpl(SqlToRelConverter.Blackboard bb, SqlToRelConverter.AggConverter aggConverter, org.apache.calcite.sql.SqlNodeList selectList, @Nullable org.apache.calcite.sql.SqlNodeList groupList, @Nullable org.apache.calcite.sql.SqlNode having, List<org.apache.calcite.sql.SqlNode> orderExprList) protected org.apache.calcite.rel.RelNodecreateAggregate(SqlToRelConverter.Blackboard bb, org.apache.calcite.util.ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<org.apache.calcite.util.ImmutableBitSet> groupSets, List<org.apache.calcite.rel.core.AggregateCall> aggCalls) Creates an Aggregate.protected SqlToRelConverter.BlackboardcreateBlackboard(@Nullable org.apache.calcite.sql.validate.SqlValidatorScope scope, @Nullable Map<String, org.apache.calcite.rex.RexNode> nameToNodeMap, boolean top) Factory method for creating translation workspace.protected org.apache.calcite.rel.RelNodecreateJoin(SqlToRelConverter.Blackboard bb, org.apache.calcite.rel.RelNode leftRel, org.apache.calcite.rel.RelNode rightRel, org.apache.calcite.rex.RexNode joinCond, org.apache.calcite.rel.core.JoinRelType joinType) org.apache.calcite.rel.RelNodedecorrelate(org.apache.calcite.sql.SqlNode query, org.apache.calcite.rel.RelNode rootRel) If sub-query is correlated and decorrelation is enabled, performs decorrelation.protected org.apache.calcite.rel.RelNodedecorrelateQuery(org.apache.calcite.rel.RelNode rootRel) protected booleanDeprecated.protected voidextraSelectItems(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select, List<org.apache.calcite.rex.RexNode> exprList, List<String> nameList, Collection<String> aliasList, List<org.apache.calcite.sql.validate.SqlMonotonicity> columnMonotonicityList) Adds extra select items.org.apache.calcite.rel.RelNodeflattenTypes(org.apache.calcite.rel.RelNode rootRel, boolean restructure) protected voidgatherOrderExprs(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select, @Nullable org.apache.calcite.sql.SqlNodeList orderList, List<org.apache.calcite.sql.SqlNode> extraOrderExprs, List<org.apache.calcite.rel.RelFieldCollation> collationList) Creates a list of collations required to implement the ORDER BY clause, if there is one.org.apache.calcite.plan.RelOptClusterReturns the RelOptCluster in use.intReturns the number of dynamic parameters encountered during translation; this must only be called afterconvertQuery(org.apache.calcite.sql.SqlNode, boolean, boolean).intgetDynamicParamCountInExplain(boolean increment) Returns the current count of the number of dynamic parameters in an EXPLAIN PLAN statement.org.apache.calcite.rel.type.RelDataTypegetDynamicParamType(int index) Returns the type inferred for a dynamic parameter.protected intDeprecated.Map<org.apache.calcite.sql.SqlNode,org.apache.calcite.rex.RexNode> Returns the mapping of non-correlated sub-queries that have been converted to the constants that they evaluate to.org.apache.calcite.rex.RexBuilderReturns the row-expression builder.protected List<org.apache.calcite.rel.type.RelDataTypeField>Returns a list of fields to be prefixed to each relational expression.protected org.apache.calcite.plan.RelOptTablegetTargetTable(org.apache.calcite.sql.SqlNode call) static booleanisOrdered(org.apache.calcite.sql.SqlNode query) booleanDeprecated.protected org.apache.calcite.sql2rel.RelFieldTrimmerCreates a RelFieldTrimmer.voidsetDynamicParamCountInExplain(int explainParamCount) Sets the number of dynamic parameters in the current EXPLAIN PLAN statement.voidsetSubQueryConverter(org.apache.calcite.sql2rel.SubQueryConverter converter) Sets a new SubQueryConverter.org.apache.calcite.rel.RelNodeorg.apache.calcite.rel.RelNodetrimUnusedFields(boolean ordered, org.apache.calcite.rel.RelNode rootRel) Walks over a tree of relational expressions, replacing eachRelNodewith a 'slimmed down' relational expression that projects only the fields required by its consumer.
-
Field Details
-
CONFIG
Default configuration. -
SQL2REL_LOGGER
protected static final org.slf4j.Logger SQL2REL_LOGGER -
DEFAULT_IN_SUB_QUERY_THRESHOLD
public static final int DEFAULT_IN_SUB_QUERY_THRESHOLDSize of the smallest IN list that will be converted to a semijoin to a static table.- See Also:
-
DEFAULT_IN_SUBQUERY_THRESHOLD
Deprecated.- See Also:
-
validator
public final @Nullable org.apache.calcite.sql.validate.SqlValidator validator -
rexBuilder
protected final org.apache.calcite.rex.RexBuilder rexBuilder -
catalogReader
protected final org.apache.calcite.prepare.Prepare.CatalogReader catalogReader -
cluster
protected final org.apache.calcite.plan.RelOptCluster cluster -
leaves
-
typeFactory
protected final org.apache.calcite.rel.type.RelDataTypeFactory typeFactory -
config
-
viewExpander
public final org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander
-
-
Constructor Details
-
SqlToRelConverter
@Deprecated public SqlToRelConverter(org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander, org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.plan.RelOptPlanner planner, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.sql2rel.SqlRexConvertletTable convertletTable) Deprecated.Creates a converter.- Parameters:
viewExpander- Preparing statementvalidator- ValidatorcatalogReader- Schemaplanner- PlannerrexBuilder- Rex builderconvertletTable- Expression converter
-
SqlToRelConverter
@Deprecated public SqlToRelConverter(org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander, org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.sql2rel.SqlRexConvertletTable convertletTable) Deprecated. -
SqlToRelConverter
public SqlToRelConverter(org.apache.calcite.plan.RelOptTable.ViewExpander viewExpander, @Nullable org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.sql2rel.SqlRexConvertletTable convertletTable, SqlToRelConverter.Config config)
-
-
Method Details
-
getCluster
public org.apache.calcite.plan.RelOptCluster getCluster()Returns the RelOptCluster in use. -
getRexBuilder
public org.apache.calcite.rex.RexBuilder getRexBuilder()Returns the row-expression builder. -
getDynamicParamCount
public int getDynamicParamCount()Returns the number of dynamic parameters encountered during translation; this must only be called afterconvertQuery(org.apache.calcite.sql.SqlNode, boolean, boolean).- Returns:
- number of dynamic parameters
-
getDynamicParamType
public org.apache.calcite.rel.type.RelDataType getDynamicParamType(int index) Returns the type inferred for a dynamic parameter.- Parameters:
index- 0-based index of dynamic parameter- Returns:
- inferred type, never null
-
getDynamicParamCountInExplain
public int getDynamicParamCountInExplain(boolean increment) Returns the current count of the number of dynamic parameters in an EXPLAIN PLAN statement.- Parameters:
increment- if true, increment the count- Returns:
- the current count before the optional increment
-
getMapConvertedNonCorrSubqs
public Map<org.apache.calcite.sql.SqlNode,org.apache.calcite.rex.RexNode> getMapConvertedNonCorrSubqs()Returns the mapping of non-correlated sub-queries that have been converted to the constants that they evaluate to. -
addConvertedNonCorrSubqs
public void addConvertedNonCorrSubqs(Map<org.apache.calcite.sql.SqlNode, org.apache.calcite.rex.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.- Parameters:
alreadyConvertedNonCorrSubqs- the other map
-
setSubQueryConverter
public void setSubQueryConverter(org.apache.calcite.sql2rel.SubQueryConverter converter) Sets a new SubQueryConverter. To have any effect, this must be called before any convert method.- Parameters:
converter- new SubQueryConverter
-
setDynamicParamCountInExplain
public void setDynamicParamCountInExplain(int explainParamCount) Sets the number of dynamic parameters in the current EXPLAIN PLAN statement.- Parameters:
explainParamCount- number of dynamic parameters in the statement
-
flattenTypes
public org.apache.calcite.rel.RelNode flattenTypes(org.apache.calcite.rel.RelNode rootRel, boolean restructure) -
decorrelate
public org.apache.calcite.rel.RelNode decorrelate(org.apache.calcite.sql.SqlNode query, org.apache.calcite.rel.RelNode rootRel) If sub-query is correlated and decorrelation is enabled, performs decorrelation.- Parameters:
query- QueryrootRel- Root relational expression- Returns:
- New root relational expression after decorrelation
-
trimUnusedFields
public org.apache.calcite.rel.RelNode trimUnusedFields(boolean ordered, org.apache.calcite.rel.RelNode rootRel) Walks over a tree of relational expressions, replacing eachRelNodewith 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.
- Parameters:
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 tree- Returns:
- Trimmed relational expression
-
newFieldTrimmer
protected org.apache.calcite.sql2rel.RelFieldTrimmer newFieldTrimmer()Creates a RelFieldTrimmer.- Returns:
- Field trimmer
-
convertQuery
public org.apache.calcite.rel.RelRoot convertQuery(org.apache.calcite.sql.SqlNode query, boolean needsValidation, boolean top) Converts an unvalidated query's parse tree into a relational expression.- Parameters:
query- Query to convertneedsValidation- Whether to validate the query before converting;falseif the query has already been validated.top- Whether the query is top-level, say if its result will become a JDBC result set;falseif the query will be part of a view.
-
isOrdered
public static boolean isOrdered(org.apache.calcite.sql.SqlNode query) -
convertSelect
public org.apache.calcite.rel.RelNode convertSelect(org.apache.calcite.sql.SqlSelect select, boolean top) Converts a SELECT statement's parse tree into a relational expression. -
createBlackboard
protected SqlToRelConverter.Blackboard createBlackboard(@Nullable org.apache.calcite.sql.validate.SqlValidatorScope scope, @Nullable Map<String, org.apache.calcite.rex.RexNode> nameToNodeMap, boolean top) Factory method for creating translation workspace. -
convertSelectImpl
protected void convertSelectImpl(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select) Implementation ofconvertSelect(SqlSelect, boolean); derived class may override. -
convertOrder
protected void convertOrder(org.apache.calcite.sql.SqlSelect select, SqlToRelConverter.Blackboard bb, org.apache.calcite.rel.RelCollation collation, List<org.apache.calcite.sql.SqlNode> orderExprList, @Nullable org.apache.calcite.sql.SqlNode offset, @Nullable org.apache.calcite.sql.SqlNode fetch) Converts a query's ORDER BY clause, if any.Ignores the ORDER BY clause if the query is not top-level and FETCH or OFFSET are not present.
- Parameters:
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 fetch
-
convertToSingleValueSubq
public org.apache.calcite.rel.RelNode convertToSingleValueSubq(org.apache.calcite.sql.SqlNode query, org.apache.calcite.rel.RelNode plan) Converts the RelNode tree for a select statement to a select that produces a single value.- Parameters:
query- the queryplan- the original RelNode tree corresponding to the statement- Returns:
- the converted RelNode tree
-
getInSubqueryThreshold
Deprecated.Gets the list size threshold under whichconvertInToOr(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 cases- Returns:
- threshold, default
DEFAULT_IN_SUB_QUERY_THRESHOLD
-
convertExpression
public org.apache.calcite.rex.RexNode convertExpression(org.apache.calcite.sql.SqlNode node) Converts an expression fromSqlNodetoRexNodeformat.- Parameters:
node- Expression to translate- Returns:
- Converted expression
-
convertExpression
public org.apache.calcite.rex.RexNode convertExpression(org.apache.calcite.sql.SqlNode node, Map<String, org.apache.calcite.rex.RexNode> nameToNodeMap) Converts an expression fromSqlNodetoRexNodeformat, mapping identifier references to predefined expressions.- Parameters:
node- Expression to translatenameToNodeMap- map from String toRexNode; when anSqlIdentifieris encountered, it is used as a key and translated to the corresponding value from this map- Returns:
- Converted expression
-
convertExtendedExpression
protected @Nullable org.apache.calcite.rex.RexNode convertExtendedExpression(org.apache.calcite.sql.SqlNode node, SqlToRelConverter.Blackboard bb) Converts a non-standard expression.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.
- Parameters:
node- Expressionbb- Blackboard- Returns:
- null to proceed with the usual expression translation process
-
convertFrom
protected void convertFrom(SqlToRelConverter.Blackboard bb, @Nullable org.apache.calcite.sql.SqlNode from) -
containsQueryHints
public void containsQueryHints()To tell this converter that this SqlNode tree contains query hints and then a query block alias will be attached to the root node of the query block.The `containsQueryHints` is false default to be compatible with previous behavior and then planner can reuse some node.
TODO At present, it is a relatively hacked way
-
convertFrom
protected void convertFrom(SqlToRelConverter.Blackboard bb, @Nullable org.apache.calcite.sql.SqlNode from, @Nullable List<String> fieldNames) Converts a FROM clause into a relational expression.- Parameters:
bb- Scope within which to resolve identifiersfrom- FROM clause of a query. Examples include:- a single table ("SALES.EMP"),
- an aliased table ("EMP AS E"),
- a list of tables ("EMP, DEPT"),
- an ANSI Join expression ("EMP JOIN DEPT ON EMP.DEPTNO = DEPT.DEPTNO"),
- a VALUES clause ("VALUES ('Fred', 20)"),
- a query ("(SELECT * FROM EMP WHERE GENDER = 'F')"),
- or any combination of the above.
fieldNames- Field aliases, usually come from AS clause, or null
-
convertMatchRecognize
protected void convertMatchRecognize(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlMatchRecognize matchRecognize) -
convertPivot
-
convertUnpivot
protected void convertUnpivot(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlUnpivot unpivot) -
convertCollectionTable
protected void convertCollectionTable(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlCall call) -
afterTableFunction
protected void afterTableFunction(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlCall call, org.apache.calcite.rel.logical.LogicalTableFunctionScan callRel) -
createJoin
protected org.apache.calcite.rel.RelNode createJoin(SqlToRelConverter.Blackboard bb, org.apache.calcite.rel.RelNode leftRel, org.apache.calcite.rel.RelNode rightRel, org.apache.calcite.rex.RexNode joinCond, org.apache.calcite.rel.core.JoinRelType joinType) -
getSystemFields
Returns a list of fields to be prefixed to each relational expression.- Returns:
- List of system fields
-
convertAgg
protected void convertAgg(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select, List<org.apache.calcite.sql.SqlNode> orderExprList) Converts the SELECT, GROUP BY and HAVING clauses of an aggregate query.This method extracts SELECT, GROUP BY and HAVING clauses, and creates an
SqlToRelConverter.AggConverter, then delegates tocreateAggImpl(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 differentSqlToRelConverter.AggConverter.- Parameters:
bb- Scope within which to resolve identifiersselect- QueryorderExprList- Additional expressions needed to implement ORDER BY
-
createAggImpl
protected final void createAggImpl(SqlToRelConverter.Blackboard bb, SqlToRelConverter.AggConverter aggConverter, org.apache.calcite.sql.SqlNodeList selectList, @Nullable org.apache.calcite.sql.SqlNodeList groupList, @Nullable org.apache.calcite.sql.SqlNode having, List<org.apache.calcite.sql.SqlNode> orderExprList) -
createAggregate
protected org.apache.calcite.rel.RelNode createAggregate(SqlToRelConverter.Blackboard bb, org.apache.calcite.util.ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<org.apache.calcite.util.ImmutableBitSet> groupSets, List<org.apache.calcite.rel.core.AggregateCall> aggCalls) Creates an Aggregate.In case the aggregate rel changes the order in which it projects fields, the
groupExprProjectionparameter is provided, and the implementation of this method may modify it.The
sortedCountparameter 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.- Parameters:
bb- BlackboardgroupSet- Bit set of ordinals of grouping columnsgroupSets- Grouping setsaggCalls- Array of calls to aggregate functions- Returns:
- LogicalAggregate
-
convertDynamicParam
public org.apache.calcite.rex.RexDynamicParam convertDynamicParam(org.apache.calcite.sql.SqlDynamicParam dynamicParam) -
gatherOrderExprs
protected void gatherOrderExprs(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select, @Nullable org.apache.calcite.sql.SqlNodeList orderList, List<org.apache.calcite.sql.SqlNode> extraOrderExprs, List<org.apache.calcite.rel.RelFieldCollation> collationList) Creates a list of collations required to implement the ORDER BY clause, if there is one. PopulatesextraOrderExprswith any sort expressions which are not in the select clause.- Parameters:
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)
-
convertOrderItem
protected org.apache.calcite.rel.RelFieldCollation convertOrderItem(org.apache.calcite.sql.SqlSelect select, org.apache.calcite.sql.SqlNode orderItem, List<org.apache.calcite.sql.SqlNode> extraExprs, org.apache.calcite.rel.RelFieldCollation.Direction direction, org.apache.calcite.rel.RelFieldCollation.NullDirection nullDirection) -
enableDecorrelation
Deprecated. -
decorrelateQuery
protected org.apache.calcite.rel.RelNode decorrelateQuery(org.apache.calcite.rel.RelNode rootRel) -
isTrimUnusedFields
Deprecated.Returns whether to trim unused fields as part of the conversion process.- Returns:
- Whether to trim unused fields
-
convertQueryRecursive
protected org.apache.calcite.rel.RelRoot convertQueryRecursive(org.apache.calcite.sql.SqlNode query, boolean top, @Nullable org.apache.calcite.rel.type.RelDataType targetRowType) Recursively converts a query to a relational expression.- Parameters:
query- Querytop- Whether this query is the top-level query of the statementtargetRowType- Target row type, or null- Returns:
- Relational expression
-
convertSetOp
protected org.apache.calcite.rel.RelNode convertSetOp(org.apache.calcite.sql.SqlCall call) Converts a set operation (UNION, INTERSECT, MINUS) into relational expressions.- Parameters:
call- Call to set operator- Returns:
- Relational expression
-
convertInsert
protected org.apache.calcite.rel.RelNode convertInsert(org.apache.calcite.sql.SqlInsert call) -
toRel
public org.apache.calcite.rel.RelNode toRel(org.apache.calcite.plan.RelOptTable table, List<org.apache.calcite.rel.hint.RelHint> hints) -
getTargetTable
protected org.apache.calcite.plan.RelOptTable getTargetTable(org.apache.calcite.sql.SqlNode call) -
convertColumnList
protected org.apache.calcite.rel.RelNode convertColumnList(org.apache.calcite.sql.SqlInsert call, org.apache.calcite.rel.RelNode source) Creates a source for an INSERT statement.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.
- Parameters:
call- Insert expressionsource- Source relational expression- Returns:
- Converted INSERT statement
-
collectInsertTargets
protected void collectInsertTargets(org.apache.calcite.sql.SqlInsert call, org.apache.calcite.rex.RexNode sourceRef, List<String> targetColumnNames, List<org.apache.calcite.rex.RexNode> columnExprs) Given an INSERT statement, collects the list of names to be populated and the expressions to put in them.- Parameters:
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 populated
-
adjustInputRef
protected org.apache.calcite.rex.RexNode adjustInputRef(SqlToRelConverter.Blackboard bb, org.apache.calcite.rex.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.- Parameters:
bb- BlackboardinputRef- Input ref- Returns:
- Adjusted input ref
-
extraSelectItems
protected void extraSelectItems(SqlToRelConverter.Blackboard bb, org.apache.calcite.sql.SqlSelect select, List<org.apache.calcite.rex.RexNode> exprList, List<String> nameList, Collection<String> aliasList, List<org.apache.calcite.sql.validate.SqlMonotonicity> columnMonotonicityList) Adds extra select items. The default implementation adds nothing; derived classes may add columns to exprList, nameList, aliasList and columnMonotonicityList.- Parameters:
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 column
-
convertWith
public org.apache.calcite.rel.RelRoot convertWith(org.apache.calcite.sql.SqlWith with, boolean top) Converts a WITH sub-query into a relational expression. -
convertValues
public org.apache.calcite.rel.RelNode convertValues(org.apache.calcite.sql.SqlCall values, @Nullable org.apache.calcite.rel.type.RelDataType targetRowType) Converts a SELECT statement's parse tree into a relational expression. -
config
Returns a defaultSqlToRelConverter.Config.
-