Package org.apache.calcite.rel.rel2sql
Class SqlImplementor
java.lang.Object
org.apache.calcite.rel.rel2sql.SqlImplementor
- Direct Known Subclasses:
RelToSqlConverter
State for generating a SQL statement.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Implementation of Context that precedes field references with their "table alias" based on the current sub-query's FROM clause.protected class
Implementation ofSqlImplementor.Context
that has an enclosingSqlImplementor
and can therefore do non-trivial expressions.class
Builder.static enum
Clauses in a SQL query.static class
class
Context for translating MATCH_RECOGNIZE clause.class
Result of implementing a node.static class
Simple implementation ofSqlImplementor.Context
that cannot handle sub-queries or correlations. -
Field Summary
Modifier and TypeFieldDescriptionprotected final Map<CorrelationId,
SqlImplementor.Context> final SqlDialect
static final SqlParserPos
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSelect
(List<SqlNode> selectList, SqlNode node, RelDataType rowType) aliasContext
(Map<String, RelDataType> aliases, boolean qualified) protected SqlCall
Convenience method for creating column and table aliases.static SqlNode
convertConditionToSqlNode
(RexNode node, SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) protected boolean
isAnon()
Returns whether to remove trivial aliases such as "EXPR$0" when converting the current relational expression into a SELECT.static boolean
isStar
(List<RexNode> exps, RelDataType inputRowType, RelDataType projectRowType) Returns whether a list of expressions projects all fields, in order, from the input, with the same names.static boolean
isStar
(RexProgram program) joinContext
(SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) static JoinType
joinType
(JoinRelType joinType) protected SqlImplementor.Result
result
(SqlNode node, Collection<SqlImplementor.Clause> clauses, @Nullable String neededAlias, @Nullable RelDataType neededType, Map<String, RelDataType> aliases) Factory method forSqlImplementor.Result
.result
(SqlNode node, Collection<SqlImplementor.Clause> clauses, RelNode rel, @Nullable Map<String, RelDataType> aliases) Creates a result based on a single relational expression.result
(SqlNode join, SqlImplementor.Result leftResult, SqlImplementor.Result rightResult) Creates a result based on a join.setOpToSql
(SqlSetOperator operator, RelNode rel) tableFunctionScanContext
(List<SqlNode> inputSqlNodes) static SqlNode
toSql
(@Nullable RexProgram program, RexLiteral literal) static SqlNode
toSql
(RexLiteral literal) Converts aRexLiteral
to aSqlLiteral
.final SqlImplementor.Result
visitChild
(int i, RelNode e) Deprecated.final SqlImplementor.Result
visitInput
(RelNode e, int i) Visits an input of the current relational expression, deducinganon
usingisAnon()
.abstract SqlImplementor.Result
visitInput
(RelNode e, int i, boolean anon, boolean ignoreClauses, Set<SqlImplementor.Clause> expectedClauses) Visits thei
th input ofe
, the current relational expression.final SqlImplementor.Result
visitInput
(RelNode e, int i, Set<SqlImplementor.Clause> clauses) Visits an input of the current relational expression, deducinganon
usingisAnon()
.final SqlImplementor.Result
visitInput
(RelNode e, int i, SqlImplementor.Clause... clauses) Visits an input of the current relational expression, with the given expected clauses.final SqlImplementor.Result
Visits a relational expression that has no parent.
-
Field Details
-
POS
-
dialect
-
aliasSet
-
correlTableMap
-
-
Constructor Details
-
SqlImplementor
-
-
Method Details
-
visitRoot
Visits a relational expression that has no parent. -
visitChild
Deprecated.Use eithervisitRoot(RelNode)
orvisitInput(RelNode, int)
. -
visitInput
Visits an input of the current relational expression, deducinganon
usingisAnon()
. -
visitInput
Visits an input of the current relational expression, with the given expected clauses. -
visitInput
Visits an input of the current relational expression, deducinganon
usingisAnon()
. -
visitInput
public abstract SqlImplementor.Result visitInput(RelNode e, int i, boolean anon, boolean ignoreClauses, Set<SqlImplementor.Clause> expectedClauses) Visits thei
th input ofe
, the current relational expression.- Parameters:
e
- 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:
-
addSelect
-
as
Convenience method for creating column and table aliases.AS(e, "c")
creates "e AS c";AS(e, "t", "c1", "c2"
creates "e AS t (c1, c2)". -
isStar
public static boolean isStar(List<RexNode> exps, RelDataType inputRowType, RelDataType projectRowType) Returns whether a list of expressions projects all fields, in order, from the input, with the same names. -
isStar
-
setOpToSql
-
convertConditionToSqlNode
public static SqlNode convertConditionToSqlNode(RexNode node, SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) - Parameters:
node
- Join conditionleftContext
- Left contextrightContext
- Right context- Returns:
- SqlNode that represents the condition
-
joinType
-
result
public SqlImplementor.Result result(SqlNode node, Collection<SqlImplementor.Clause> clauses, RelNode rel, @Nullable Map<String, RelDataType> aliases) Creates a result based on a single relational expression. -
result
protected SqlImplementor.Result result(SqlNode node, Collection<SqlImplementor.Clause> clauses, @Nullable String neededAlias, @Nullable RelDataType neededType, Map<String, RelDataType> aliases) Factory method forSqlImplementor.Result
.Call this method rather than creating a
Result
directly, because sub-classes may override. -
result
public SqlImplementor.Result result(SqlNode join, SqlImplementor.Result leftResult, SqlImplementor.Result rightResult) Creates a result based on a join. (Each join could contain one or more relational expressions.) -
isAnon
protected boolean isAnon()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
-
toSql
-
toSql
Converts aRexLiteral
to aSqlLiteral
. -
aliasContext
-
joinContext
public SqlImplementor.Context joinContext(SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) -
matchRecognizeContext
-
tableFunctionScanContext
-
visitRoot(RelNode)
orvisitInput(RelNode, int)
.