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
Nested ClassesModifier and TypeClassDescriptionclassImplementation of Context that precedes field references with their "table alias" based on the current sub-query's FROM clause.protected classImplementation ofSqlImplementor.Contextthat has an enclosingSqlImplementorand can therefore do non-trivial expressions.classBuilder.static enumClauses in a SQL query.static classclassContext for translating MATCH_RECOGNIZE clause.classResult of implementing a node.static classSimple implementation ofSqlImplementor.Contextthat cannot handle sub-queries or correlations. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<CorrelationId,SqlImplementor.Context> final SqlDialectstatic final SqlParserPos -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSelect(List<SqlNode> selectList, SqlNode node, RelDataType rowType) aliasContext(Map<String, RelDataType> aliases, boolean qualified) protected SqlCallConvenience method for creating column and table aliases.static SqlNodeconvertConditionToSqlNode(RexNode node, SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) protected SqlImplementor.ContextgetAliasContext(RexCorrelVariable variable) protected booleanisAnon()Returns whether to remove trivial aliases such as "EXPR$0" when converting the current relational expression into a SELECT.static booleanisStar(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 booleanisStar(RexProgram program) joinContext(SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) static JoinTypejoinType(JoinRelType joinType) protected SqlImplementor.Resultresult(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 SqlNodetoSql(@Nullable RexProgram program, RexLiteral literal) static SqlNodetoSql(RexLiteral literal) Converts aRexLiteralto aSqlLiteral.final SqlImplementor.ResultvisitChild(int i, RelNode e) Deprecated.final SqlImplementor.ResultvisitInput(RelNode e, int i) Visits an input of the current relational expression, deducinganonusingisAnon().abstract SqlImplementor.ResultvisitInput(RelNode e, int i, boolean anon, boolean ignoreClauses, Set<SqlImplementor.Clause> expectedClauses) Visits theith input ofe, the current relational expression.final SqlImplementor.ResultvisitInput(RelNode e, int i, Set<SqlImplementor.Clause> clauses) Visits an input of the current relational expression, deducinganonusingisAnon().final SqlImplementor.ResultvisitInput(RelNode e, int i, SqlImplementor.Clause... clauses) Visits an input of the current relational expression, with the given expected clauses.final SqlImplementor.ResultVisits a relational expression that has no parent.windowTableFunctionScanContext(SqlNode inputTableNode, List<SqlNode> inputFieldNodes)
-
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, deducinganonusingisAnon(). -
visitInput
Visits an input of the current relational expression, with the given expected clauses. -
visitInput
Visits an input of the current relational expression, deducinganonusingisAnon(). -
visitInput
public abstract SqlImplementor.Result visitInput(RelNode e, int i, boolean anon, boolean ignoreClauses, Set<SqlImplementor.Clause> expectedClauses) Visits theith input ofe, the current relational expression.- Parameters:
e- Current relational expressioni- Ordinal of input withineanon- 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
Resultdirectly, 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 t2rather than with it:
INSERT INTO t1 SELECT x, y + 1 AS EXPR$0 FROM t2But 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$0because 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 aRexLiteralto aSqlLiteral. -
getAliasContext
-
aliasContext
-
joinContext
public SqlImplementor.Context joinContext(SqlImplementor.Context leftContext, SqlImplementor.Context rightContext) -
matchRecognizeContext
-
tableFunctionScanContext
-
windowTableFunctionScanContext
public SqlImplementor.Context windowTableFunctionScanContext(SqlNode inputTableNode, List<SqlNode> inputFieldNodes)
-
visitRoot(RelNode)orvisitInput(RelNode, int).