Class SqlCall
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
SqlAlter
,SqlAttributeDefinition
,SqlBasicCall
,SqlCase
,SqlCheckConstraint
,SqlColumnDeclaration
,SqlDdl
,SqlDelete
,SqlDescribeSchema
,SqlDescribeTable
,SqlExplain
,SqlHint
,SqlInsert
,SqlJoin
,SqlKeyConstraint
,SqlMatchRecognize
,SqlMerge
,SqlOrderBy
,SqlPivot
,SqlSelect
,SqlSnapshot
,SqlTableRef
,SqlUnpivot
,SqlUpdate
,SqlWindow
,SqlWith
,SqlWithItem
SqlCall
is a call to an operator
.
(Operators can be used to describe any syntactic construct, so in practice,
every non-leaf node in a SQL parse tree is a SqlCall
of some
kind.)-
Field Summary
Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(SqlVisitor<R> visitor) Accepts a generic visitor.clone
(SqlParserPos pos) Clones a SqlNode with a different position.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.protected String
getCallSignature
(SqlValidator validator, @Nullable SqlValidatorScope scope) Returns a string describing the actual argument types of a call, e.g.@Nullable SqlLiteral
getKind()
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special.getMonotonicity
(@Nullable SqlValidatorScope scope) Returns whether expression is always ascending, descending or constant.Returns the list of operands.abstract SqlOperator
boolean
Returns whether it is the functionCOUNT(*)
.boolean
Whether this call was created by expanding a parentheses-free call to what was syntactically an identifier.<S extends SqlNode>
Soperand
(int i) Returns i-th operand (0-based).int
void
setOperand
(int i, @Nullable SqlNode operand) Changes the value of an operand.void
Writes a SQL representation of this node to a writer.void
validate
(SqlValidator validator, SqlValidatorScope scope) Validates this call.Methods inherited from class org.apache.calcite.sql.SqlNode
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, getParserPosition, isA, toList, toList, toSqlString, toSqlString, toSqlString, toString, unparseWithParentheses, validateExpr
-
Constructor Details
-
SqlCall
-
-
Method Details
-
isExpanded
public boolean isExpanded()Whether this call was created by expanding a parentheses-free call to what was syntactically an identifier. -
setOperand
Changes the value of an operand. Allows some rewrite bySqlValidator
; use sparingly.- Parameters:
i
- Operand indexoperand
- Operand value
-
getKind
Description copied from class:SqlNode
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special. -
getOperator
-
getOperandList
Returns the list of operands. The set and order of operands is call-specific.Note: the proper type would be
List<@Nullable SqlNode>
, however, it would trigger too many changes to the current codebase.- Returns:
- the list of call operands, never null, the operands can be null
-
operand
Returns i-th operand (0-based).Note: the result might be null, so the proper signature would be
<S extends @Nullable SqlNode>
, however, it would trigger to many changes to the current codebase.- Type Parameters:
S
- type of the result- Parameters:
i
- operand index (0-based)- Returns:
- i-th operand (0-based), the result might be null
-
operandCount
public int operandCount() -
clone
Description copied from class:SqlNode
Clones a SqlNode with a different position. -
unparse
Description copied from class:SqlNode
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
unparse(org.apache.calcite.sql.SqlWriter, int, int)
. -
validate
Validates this call.The default implementation delegates the validation to the operator's
SqlOperator.validateCall(org.apache.calcite.sql.SqlCall, org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope, org.apache.calcite.sql.validate.SqlValidatorScope)
. Derived classes may override (as do, for exampleSqlSelect
andSqlUpdate
). -
findValidOptions
public void findValidOptions(SqlValidator validator, SqlValidatorScope scope, SqlParserPos pos, Collection<SqlMoniker> hintList) Description copied from class:SqlNode
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.- Overrides:
findValidOptions
in classSqlNode
- Parameters:
validator
- Validatorscope
- Validation scopepos
- SqlParserPos indicating the cursor position at which completion hints are requested forhintList
- list of valid options
-
accept
Description copied from class:SqlNode
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
Description copied from class:SqlNode
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
- Specified by:
equalsDeep
in classSqlNode
-
getCallSignature
Returns a string describing the actual argument types of a call, e.g. "SUBSTR(VARCHAR(12), NUMBER(3,2), INTEGER)". -
getMonotonicity
Description copied from class:SqlNode
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
.- Overrides:
getMonotonicity
in classSqlNode
- Parameters:
scope
- Scope
-
isCountStar
public boolean isCountStar()Returns whether it is the functionCOUNT(*)
.- Returns:
- true if function call to COUNT(*)
-
getFunctionQuantifier
-