Class SqlNode
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
SqlCall
,SqlDataTypeSpec
,SqlDynamicParam
,SqlIdentifier
,SqlIntervalQualifier
,SqlLiteral
,SqlNodeList
SqlNode
is a SQL parse tree.
It may be a
call
, literal
,
identifier
, and so forth.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract <R> R
accept
(SqlVisitor<R> visitor) Accepts a generic visitor.clone()
Deprecated.static <E extends SqlNode>
Eclone
(E e) Creates a copy of a SqlNode.abstract SqlNode
clone
(SqlParserPos pos) Clones a SqlNode with a different position.static SqlNode[]
cloneArray
(SqlNode[] nodes) Deprecated.static boolean
equalDeep
(List<? extends @Nullable SqlNode> operands0, List<? extends @Nullable SqlNode> operands1, Litmus litmus) Returns whether two lists of operands are equal, comparing usingequalsDeep(SqlNode, Litmus)
.static boolean
Returns whether two nodes are equal (usingequalsDeep(SqlNode, Litmus)
) or are both null.final boolean
equalsDeep
(@Nullable SqlNode node, boolean fail) Deprecated.abstract boolean
equalsDeep
(@Nullable SqlNode node, Litmus litmus) Returns whether this node is structurally equivalent to another node.void
findValidOptions
(SqlValidator validator, SqlValidatorScope scope, SqlParserPos pos, Collection<SqlMoniker> hintList) Lists all the valid alternatives for this node if the parse position of the node matches that of pos.getKind()
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special.getMonotonicity
(SqlValidatorScope scope) Returns whether expression is always ascending, descending or constant.final boolean
Returns whether this node is a member of an aggregate category.static <T extends SqlNode>
Collector<T,ArrayList<@Nullable SqlNode>, SqlNodeList> toList()
Returns aCollector
that accumulates the input elements into aSqlNodeList
, with zero position.static <T extends @Nullable SqlNode>
Collector<T,ArrayList<@Nullable SqlNode>, SqlNodeList> toList
(SqlParserPos pos) Returns aCollector
that accumulates the input elements into aSqlNodeList
.toSqlString
(UnaryOperator<SqlWriterConfig> transform) Returns the SQL text of the tree of which thisSqlNode
is the root.toSqlString
(@Nullable SqlDialect dialect) toSqlString
(@Nullable SqlDialect dialect, boolean forceParens) Returns the SQL text of the tree of which thisSqlNode
is the root.toString()
abstract void
Writes a SQL representation of this node to a writer.void
unparseWithParentheses
(SqlWriter writer, int leftPrec, int rightPrec, boolean parentheses) abstract void
validate
(SqlValidator validator, SqlValidatorScope scope) Validates this node.void
validateExpr
(SqlValidator validator, SqlValidatorScope scope) Validates this node in an expression context.
-
Field Details
-
EMPTY_ARRAY
-
pos
-
-
Method Details
-
clone
Deprecated.Please useclone(SqlNode)
; this method brings along too much baggage from early versions of Java -
clone
Creates a copy of a SqlNode. -
clone
Clones a SqlNode with a different position. -
getKind
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special.- Returns:
- a
SqlKind
value, never null - See Also:
-
isA
Returns whether this node is a member of an aggregate category.For example,
node.isA(SqlKind.QUERY)
returnstrue
if the node is a SELECT, INSERT, UPDATE etc.This method is shorthand:
node.isA(category)
is always equivalent tonode.getKind().belongsTo(category)
.- Parameters:
category
- Category- Returns:
- Whether this node belongs to the given category.
-
cloneArray
Deprecated. -
toString
-
toSqlString
Returns the SQL text of the tree of which thisSqlNode
is the root.Typical return values are:
- 'It''s a bird!'
- NULL
- 12.3
- DATE '1969-04-29'
- Parameters:
transform
- Transform that sets desired writer configuration
-
toSqlString
Returns the SQL text of the tree of which thisSqlNode
is the root.Typical return values are:
- 'It''s a bird!'
- NULL
- 12.3
- DATE '1969-04-29'
- Parameters:
dialect
- Dialect (null for ANSI SQL)forceParens
- Whether to wrap all expressions in parentheses; useful for parse test, but false by default
-
toSqlString
-
unparse
Writes a SQL representation of this node to a writer.The
leftPrec
andrightPrec
parameters give us enough context to decide whether we need to enclose the expression in parentheses. For example, we need parentheses around "2 + 3" if preceded by "5 *". This is because the precedence of the "*" operator is greater than the precedence of the "+" operator.The algorithm handles left- and right-associative operators by giving them slightly different left- and right-precedence.
If
SqlWriter.isAlwaysUseParentheses()
is true, we use parentheses even when they are not required by the precedence rules.For the details of this algorithm, see
SqlCall.unparse(org.apache.calcite.sql.SqlWriter, int, int)
. -
unparseWithParentheses
public void unparseWithParentheses(SqlWriter writer, int leftPrec, int rightPrec, boolean parentheses) -
getParserPosition
-
validate
Validates this node.The typical implementation of this method will make a callback to the validator appropriate to the node type and context. The validator has methods such as
SqlValidator.validateLiteral(org.apache.calcite.sql.SqlLiteral)
for these purposes.- Parameters:
scope
- Validator
-
findValidOptions
public void findValidOptions(SqlValidator validator, SqlValidatorScope scope, SqlParserPos pos, Collection<SqlMoniker> hintList) Lists all the valid alternatives for this node if the parse position of the node matches that of pos. Only implemented now for SqlCall and SqlOperator.- Parameters:
validator
- Validatorscope
- Validation scopepos
- SqlParserPos indicating the cursor position at which completion hints are requested forhintList
- list of valid options
-
validateExpr
Validates this node in an expression context.Usually, this method does much the same as
validate(org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope)
, but aSqlIdentifier
can occur in expression and non-expression contexts. -
accept
Accepts a generic visitor.Implementations of this method in subtypes simply call the appropriate
visit
method on thevisitor object
.The type parameter
R
must be consistent with the type parameter of the visitor. -
equalsDeep
Returns whether this node is structurally equivalent to another node. Some examples:- 1 + 2 is structurally equivalent to 1 + 2
- 1 + 2 + 3 is structurally equivalent to (1 + 2) + 3, but not to 1 + (2 + 3), because the '+' operator is left-associative
-
equalsDeep
Deprecated. -
equalDeep
Returns whether two nodes are equal (usingequalsDeep(SqlNode, Litmus)
) or are both null.- Parameters:
node1
- First expressionnode2
- Second expressionlitmus
- What to do if an error is detected (expressions are not equal)
-
getMonotonicity
Returns whether expression is always ascending, descending or constant. This property is useful because it allows to safely aggregate infinite streams of values.The default implementation returns
SqlMonotonicity.NOT_MONOTONIC
.- Parameters:
scope
- Scope
-
equalDeep
public static boolean equalDeep(List<? extends @Nullable SqlNode> operands0, List<? extends @Nullable SqlNode> operands1, Litmus litmus) Returns whether two lists of operands are equal, comparing usingequalsDeep(SqlNode, Litmus)
. -
toList
Returns aCollector
that accumulates the input elements into aSqlNodeList
, with zero position.- Type Parameters:
T
- Type of the input elements- Returns:
- a
Collector
that collects all the input elements into aSqlNodeList
, in encounter order
-
toList
public static <T extends @Nullable SqlNode> Collector<T,ArrayList<@Nullable SqlNode>, toListSqlNodeList> (SqlParserPos pos) Returns aCollector
that accumulates the input elements into aSqlNodeList
.- Type Parameters:
T
- Type of the input elements- Returns:
- a
Collector
that collects all the input elements into aSqlNodeList
, in encounter order
-
clone(SqlNode)
; this method brings along too much baggage from early versions of Java