public abstract class SqlNode extends Object implements Cloneable
SqlNode is a SQL parse tree.
It may be an
operator, literal,
identifier, and so forth.
| Modifier and Type | Field and Description |
|---|---|
static SqlNode[] |
EMPTY_ARRAY |
protected SqlParserPos |
pos |
| Modifier and Type | Method and Description |
|---|---|
abstract <R> R |
accept(SqlVisitor<R> visitor)
Accepts a generic visitor.
|
Object |
clone() |
SqlNode |
clone(SqlParserPos pos)
Clones a SqlNode with a different position.
|
static SqlNode[] |
cloneArray(SqlNode[] nodes) |
static boolean |
equalDeep(List<SqlNode> operands0,
List<SqlNode> operands1,
boolean fail)
Returns whether two lists of operands are equal.
|
static boolean |
equalDeep(SqlNode node1,
SqlNode node2,
boolean fail)
Returns whether two nodes are equal (using
equalsDeep(SqlNode, boolean)) or are both null. |
abstract boolean |
equalsDeep(SqlNode node,
boolean fail)
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.
|
SqlKind |
getKind()
Returns the type of node this is, or
SqlKind.OTHER if it's nothing special. |
SqlMonotonicity |
getMonotonicity(SqlValidatorScope scope)
Returns whether expression is always ascending, descending or constant.
|
SqlParserPos |
getParserPosition() |
boolean |
isA(Set<SqlKind> category)
Returns whether this node is a member of an aggregate category.
|
SqlString |
toSqlString(SqlDialect dialect) |
SqlString |
toSqlString(SqlDialect dialect,
boolean forceParens)
Returns the SQL text of the tree of which this
SqlNode is
the root. |
String |
toString() |
abstract void |
unparse(SqlWriter writer,
int leftPrec,
int rightPrec)
Writes a SQL representation of this node to a writer.
|
abstract void |
validate(SqlValidator validator,
SqlValidatorScope scope)
Validates this node.
|
void |
validateExpr(SqlValidator validator,
SqlValidatorScope scope)
Validates this node in an expression context.
|
public static final SqlNode[] EMPTY_ARRAY
protected final SqlParserPos pos
public SqlNode clone(SqlParserPos pos)
public SqlKind getKind()
SqlKind.OTHER if it's nothing special.SqlKind value, never nullisA(java.util.Set<org.apache.calcite.sql.SqlKind>)public final boolean isA(Set<SqlKind> category)
For example, node.isA(SqlKind.QUERY) returns true
if the node is a SELECT, INSERT, UPDATE etc.
This method is shorthand: node.isA(category) is always
equivalent to node.getKind().belongsTo(category).
category - Categorypublic SqlString toSqlString(SqlDialect dialect, boolean forceParens)
SqlNode is
the root.dialect - DialectforceParens - wraps all expressions in parentheses; good for parse
test, but false by default.
Typical return values are:
public SqlString toSqlString(SqlDialect dialect)
public abstract void unparse(SqlWriter writer, int leftPrec, int rightPrec)
The leftPrec and rightPrec 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).
public SqlParserPos getParserPosition()
public abstract void validate(SqlValidator validator, SqlValidatorScope scope)
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.
scope - Validatorpublic void findValidOptions(SqlValidator validator, SqlValidatorScope scope, SqlParserPos pos, Collection<SqlMoniker> hintList)
validator - Validatorscope - Validation scopepos - SqlParserPos indicating the cursor position at which
completion hints are requested forhintList - list of valid optionspublic void validateExpr(SqlValidator validator, SqlValidatorScope scope)
Usually, this method does much the same as validate(org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope), but a
SqlIdentifier can occur in expression and non-expression
contexts.
public abstract <R> R accept(SqlVisitor<R> visitor)
Implementations of this method in subtypes simply call the appropriate
visit method on the
visitor object.
The type parameter R must be consistent with the type
parameter of the visitor.
public abstract boolean equalsDeep(SqlNode node, boolean fail)
public static boolean equalDeep(SqlNode node1, SqlNode node2, boolean fail)
equalsDeep(SqlNode, boolean)) or are both null.node1 - First expressionnode2 - Second expressionfail - Whether to throw AssertionError if expressions are
not equalpublic SqlMonotonicity getMonotonicity(SqlValidatorScope scope)
The default implementation returns
SqlMonotonicity.NOT_MONOTONIC.
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.