Package org.apache.calcite.rel.rel2sql
Class RelToSqlConverter
java.lang.Object
org.apache.calcite.rel.rel2sql.SqlImplementor
org.apache.calcite.rel.rel2sql.RelToSqlConverter
- All Implemented Interfaces:
ReflectiveVisitor
- Direct Known Subclasses:
JdbcImplementor
,PigRelToSqlConverter
Utility to convert relational expressions to SQL abstract syntax tree.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.calcite.rel.rel2sql.SqlImplementor
SqlImplementor.AliasContext, SqlImplementor.BaseContext, SqlImplementor.Builder, SqlImplementor.Clause, SqlImplementor.Context, SqlImplementor.MatchRecognizeContext, SqlImplementor.Result, SqlImplementor.SimpleContext
-
Field Summary
Fields inherited from class org.apache.calcite.rel.rel2sql.SqlImplementor
aliasSet, correlTableMap, dialect, POS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSelect
(List<SqlNode> selectList, SqlNode node, RelDataType rowType) protected void
buildAggGroupList
(Aggregate e, SqlImplementor.Builder builder, List<SqlNode> groupByList, List<SqlNode> selectList) Builds the group list for an Aggregate node.protected SqlImplementor.Builder
buildAggregate
(Aggregate e, SqlImplementor.Builder builder, List<SqlNode> selectList, List<SqlNode> groupByList) Builds an aggregate query.createAsFullOperands
(RelDataType rowType, SqlNode leftOperand, String alias) Creates operands for a full AS operator.protected SqlImplementor.Result
Dispatches a call to thevisit(Xxx e)
method whereXxx
most closely matches the runtime type of the argument.boolean
hasTrickyRollup
(Sort e, Aggregate aggregate) protected boolean
isAnon()
Returns whether to remove trivial aliases such as "EXPR$0" when converting the current relational expression into a SELECT.protected SqlImplementor.Result
result
(SqlNode node, Collection<SqlImplementor.Clause> clauses, @Nullable String neededAlias, @Nullable RelDataType neededType, Map<String, RelDataType> aliases) Factory method forSqlImplementor.Result
.Visits an Aggregate; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Calc; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Correlate; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Filter; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits an Intersect; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Join; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Match; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Minus; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Project; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Sample; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Sort; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.visit
(TableModify modify) Visits a TableModify; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a TableScan; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Union; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Values; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a Window; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.Visits a RelNode; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection.protected SqlImplementor.Result
visitInput
(RelNode parent, int i, boolean anon, boolean ignoreClauses, Set<SqlImplementor.Clause> expectedClauses) Visits thei
th input ofe
, the current relational expression.Methods inherited from class org.apache.calcite.rel.rel2sql.SqlImplementor
aliasContext, as, convertConditionToSqlNode, isStar, isStar, joinContext, joinType, matchRecognizeContext, result, result, setOpToSql, tableFunctionScanContext, toSql, toSql, visitChild, visitInput, visitInput, visitInput, visitRoot
-
Constructor Details
-
RelToSqlConverter
Creates a RelToSqlConverter.
-
-
Method Details
-
dispatch
Dispatches a call to thevisit(Xxx e)
method whereXxx
most closely matches the runtime type of the argument. -
visitInput
public SqlImplementor.Result visitInput(RelNode parent, int i, boolean anon, boolean ignoreClauses, Set<SqlImplementor.Clause> expectedClauses) Description copied from class:SqlImplementor
Visits thei
th input ofe
, the current relational expression.- Specified by:
visitInput
in classSqlImplementor
- Parameters:
parent
- Current relational expressioni
- Ordinal of input withine
anon
- Whether to remove trivial aliases such as "EXPR$0"ignoreClauses
- Whether to ignore the expected clauses when deciding whether a sub-query is requiredexpectedClauses
- Set of clauses that we expect the builder that consumes this result will create- Returns:
- Result
- See Also:
-
isAnon
protected boolean isAnon()Description copied from class:SqlImplementor
Returns whether to remove trivial aliases such as "EXPR$0" when converting the current relational expression into a SELECT.For example, INSERT does not care about field names; we would prefer to generate without the "EXPR$0" alias:
INSERT INTO t1 SELECT x, y + 1 FROM t2
rather than with it:
INSERT INTO t1 SELECT x, y + 1 AS EXPR$0 FROM t2
But JOIN does care about field names; we have to generate the "EXPR$0" alias:
SELECT * FROM emp AS e JOIN (SELECT x, y + 1 AS EXPR$0) AS d ON e.deptno = d.EXPR$0
because if we omit "AS EXPR$0" we do not know the field we are joining to, and the following is invalid:
SELECT * FROM emp AS e JOIN (SELECT x, y + 1) AS d ON e.deptno = d.EXPR$0
- Overrides:
isAnon
in classSqlImplementor
-
result
protected SqlImplementor.Result result(SqlNode node, Collection<SqlImplementor.Clause> clauses, @Nullable String neededAlias, @Nullable RelDataType neededType, Map<String, RelDataType> aliases) Description copied from class:SqlImplementor
Factory method forSqlImplementor.Result
.Call this method rather than creating a
Result
directly, because sub-classes may override.- Overrides:
result
in classSqlImplementor
-
visit
Visits a RelNode; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Join; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visitAntiOrSemiJoin
-
visit
Visits a Correlate; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Filter; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Project; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Window; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits an Aggregate; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
buildAggGroupList
protected void buildAggGroupList(Aggregate e, SqlImplementor.Builder builder, List<SqlNode> groupByList, List<SqlNode> selectList) Builds the group list for an Aggregate node.- Parameters:
e
- The Aggregate nodebuilder
- The SQL buildergroupByList
- output group listselectList
- output select list
-
buildAggregate
protected SqlImplementor.Builder buildAggregate(Aggregate e, SqlImplementor.Builder builder, List<SqlNode> selectList, List<SqlNode> groupByList) Builds an aggregate query.- Parameters:
e
- The Aggregate nodebuilder
- The SQL builderselectList
- The precomputed group listgroupByList
- The precomputed select list- Returns:
- The aggregate query result
-
visit
Visits a TableScan; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Union; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits an Intersect; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Minus; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Calc; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Values; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Sample; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Sort; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
hasTrickyRollup
-
visit
Visits a TableModify; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
Visits a Match; called bydispatch(org.apache.calcite.rel.RelNode)
via reflection. -
visit
-
visit
-
createAsFullOperands
Creates operands for a full AS operator. Format SqlNode AS alias(col_1, col_2,... ,col_n).- Parameters:
rowType
- Row type of the SqlNodeleftOperand
- SqlNodealias
- alias
-
addSelect
- Overrides:
addSelect
in classSqlImplementor
-