Class SqlValidatorImpl
- All Implemented Interfaces:
SqlValidator
,SqlValidatorWithHints
- Direct Known Subclasses:
CalciteSqlValidator
,ContextSqlValidator
,SqlAdvisorValidator
SqlValidator
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Common base class for DML statement namespaces.protected static class
Utility object used to maintain information about the parameters in a function call.protected static class
Information about an identifier in a particular scope.static enum
Validation status.Nested classes/interfaces inherited from interface org.apache.calcite.sql.validate.SqlValidator
SqlValidator.Config
-
Field Summary
Modifier and TypeFieldDescriptionfinal IdentityHashMap<SqlCall,
List<RelDataType>> Provides the data forgetValidatedOperandTypes(SqlCall)
.protected final Deque<SqlValidatorImpl.FunctionParamInfo>
Stack of objects that maintain information about function calls.protected final Map<String,
SqlValidatorImpl.IdInfo> MapsSqlParserPos
strings to theSqlIdentifier
identifier objects at these positions.protected final IdentityHashMap<SqlNode,
SqlValidatorNamespace> protected final IdentityHashMap<SqlNode,
SqlValidatorScope> Mapsquery node
objects to theSqlValidatorScope
scope created from them.protected final TimeFrameSet
static final org.slf4j.Logger
protected final RelDataTypeFactory
protected final RelDataType
static final String
Alias prefix generated for source columns when rewriting UPDATE to MERGE.static final String
Alias generated for the source table when rewriting UPDATE to MERGE.static final String
Alias generated for the target table when rewriting UPDATE to MERGE if no alias was specified by the user. -
Constructor Summary
ModifierConstructorDescriptionprotected
SqlValidatorImpl
(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlValidator.Config config) Creates a validator. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToSelectList
(List<SqlNode> list, Set<String> aliases, List<Map.Entry<String, RelDataType>> fieldList, SqlNode exp, SelectScope scope, boolean includeSystemVars) Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list.protected void
checkTypeAssignment
(@Nullable SqlValidatorScope sourceScope, SqlValidatorTable table, RelDataType sourceRowType, RelDataType targetRowType, SqlNode query) Checks the type assignment of an INSERT or UPDATE query.config()
Returns the config of the validator.protected MatchRecognizeNamespace
createMatchRecognizeNameSpace
(SqlMatchRecognize call, SqlNode enclosingNode) protected PivotNamespace
createPivotNameSpace
(SqlPivot call, SqlNode enclosingNode) protected SelectNamespace
createSelectNamespace
(SqlSelect select, SqlNode enclosingNode) Creates a namespace for aSELECT
node.protected SetopNamespace
createSetopNamespace
(SqlCall call, SqlNode enclosingNode) Creates a namespace for a set operation (UNION
,INTERSECT
, orEXCEPT
).protected SqlSelect
Creates the SELECT statement that putatively feeds rows into a DELETE statement to be deleted.protected SqlSelect
Creates the SELECT statement that putatively feeds rows into an UPDATE statement to be updated.protected RelDataType
createTargetRowType
(SqlValidatorTable table, @Nullable SqlNodeList targetColumnList, boolean append, @Nullable SqlIdentifier targetTableAlias) Derives a row-type for INSERT and UPDATE operations.protected UnpivotNamespace
createUnpivotNameSpace
(SqlUnpivot call, SqlNode enclosingNode) void
declareCursor
(SqlSelect select, SqlValidatorScope parentScope) Declares a SELECT expression as a cursor.@Nullable String
deriveAlias
(SqlNode node, int ordinal) Derives an alias for an expression.deriveConstructorType
(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes) Derives the type of a constructor.deriveType
(SqlValidatorScope scope, SqlNode expr) Derives the type of a node in a given scope.expand
(SqlNode expr, SqlValidatorScope scope) Expands an expression.expandOrderExpr
(SqlSelect select, SqlNode orderExpr) Expands an expression in the ORDER BY clause into an expression with the same semantics as expressions in the SELECT clause.expandSelectExpr
(SqlNode expr, SelectScope scope, SqlSelect select) expandStar
(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars) Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded.extendedExpandGroupBy
(SqlNode expr, SqlValidatorScope scope, SqlSelect select) protected @Nullable SqlNode
getAggregate
(SqlSelect select) Returns the parse tree node (GROUP BY, HAVING, or an aggregate function call) that causesselect
to be an aggregate query, or null if it is not an aggregate query.Returns the catalog reader used by this validator.getCursorScope
(SqlSelect select) Returns a scope that cannot see anything.getFieldOrigins
(SqlNode sqlQuery) Returns a description of how each field in the row type maps to a catalog, schema, table and column in the schema.getFromScope
(SqlSelect select) Returns a scope containing the objects visible from the FROM clause of a query.getGroupScope
(SqlSelect select) Returns a scope containing the objects visible from the GROUP BY clause of a query.getHavingScope
(SqlSelect select) Returns a scope containing the objects visible from the HAVING clause of a query.getJoinScope
(SqlNode node) Returns a scope containing the objects visible from the ON and USING sections of a JOIN clause.getLambdaScope
(SqlLambda node) Returns the lambda expression scope.protected RelDataType
getLogicalSourceRowType
(RelDataType sourceRowType, SqlInsert insert) protected RelDataType
getLogicalTargetRowType
(RelDataType targetRowType, SqlInsert insert) Returns a scope match recognize clause.getMeasureScope
(SqlSelect select) @Nullable SqlValidatorNamespace
getNamespace
(SqlNode node) Finds the namespace corresponding to a given node.Returns the operator table used by this validator.getOrderScope
(SqlSelect select) Returns the scope that expressions in the SELECT and HAVING clause of this query should use.getOriginal
(SqlNode expr) getOverScope
(SqlNode node) Returns the scope of an OVER or VALUES node.getParameterRowType
(SqlNode sqlQuery) Returns a record type that contains the name and type of each parameter.@Nullable String
getParentCursor
(String columnListParamName) Retrieves the name of the parent cursor referenced by a column list parameter.@Nullable SelectScope
getRawSelectScope
(SqlSelect select) Returns the scope for resolving the SELECT, GROUP BY and HAVING clauses.getSelectScope
(SqlSelect select) Returns the appropriate scope for validating a particular clause of a SELECT statement.protected @Nullable SqlNode
getSelfJoinExprForUpdate
(SqlNode table, String alias) Allows a subclass to provide information about how to convert an UPDATE into a MERGE via self-join.Returns the set of allowed time frames.Get the type coercion instance.Returns the type factory used by this validator.Returns an object representing the "unknown" type.getValidatedNodeType
(SqlNode node) Returns the type assigned to a node by validation.@Nullable RelDataType
Returns the type assigned to a node by validation, or null if unknown.@Nullable List<RelDataType>
Returns the types of a call's operands.org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationErrorFunction
getWhereScope
(SqlSelect select) Returns the scope that expressions in the WHERE and GROUP BY clause of this query should use.protected SqlWindow
getWindowByName
(SqlIdentifier id, SqlValidatorScope scope) getWithScope
(SqlNode withItem) handleUnresolvedFunction
(SqlCall call, SqlOperator unresolvedFunction, List<RelDataType> argTypes, @Nullable List<String> argNames) Handles a call to a function which cannot be resolved.protected void
inferUnknownTypes
(RelDataType inferredType, SqlValidatorScope scope, SqlNode node) boolean
isAggregate
(SqlNode selectNode) Deprecated.boolean
isAggregate
(SqlSelect select) Returns whether a SELECT statement is an aggregation.protected boolean
protected boolean
isOverAggregateWindow
(SqlNode node) boolean
isSystemField
(RelDataTypeField field) Returns whether a field is a system field.lookupHints
(SqlNode topNode, SqlParserPos pos) Looks up completion hints for a syntactically correct SQL statement that has been parsed into an expression tree.final void
lookupNameCompletionHints
(SqlValidatorScope scope, List<String> names, SqlParserPos pos, Collection<SqlMoniker> hintList) Populates a list of all the valid alternatives for an identifier.@Nullable SqlMoniker
lookupQualifiedName
(SqlNode topNode, SqlParserPos pos) Looks up the fully qualified name for aSqlIdentifier
at a given Parser Position in a parsed expression tree Note: call this only afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)
has been called.@Nullable SqlCall
If an identifier is a legitimate call to a function that has no arguments and requires no parentheses (for example "CURRENT_USER"), returns a call to that function, otherwise returns null.newValidationError
(SqlNode node, org.apache.calcite.runtime.Resources.ExInst<SqlValidatorException> e) Adds "line x, column y" context to a validator exception.protected @PolyNull SqlNode
performUnconditionalRewrites
(@PolyNull SqlNode node, boolean underFrom) Performs expression rewrites which are always used unconditionally.void
Removes the topmost entry from the function call stack.void
Pushes a new instance of a function call on to a function call stack.protected void
registerNamespace
(@Nullable SqlValidatorScope usingScope, @Nullable String alias, SqlValidatorNamespace ns, boolean forceNullable) Registers a new namespace, and adds it as a child of its parent scope.protected void
registerQuery
(SqlValidatorScope parentScope, @Nullable SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, @Nullable String alias, boolean forceNullable) Registers a query in a parent scope.void
Removes a node from the set of validated nodes.resolveLiteral
(SqlLiteral literal) Resolves a literal.resolveWindow
(SqlNode windowOrRef, SqlValidatorScope scope) Converts a window specification or window name into a fully-resolved window specification.void
setOriginal
(SqlNode expr, SqlNode original) final void
setValidatedNodeType
(SqlNode node, RelDataType type) Saves the type of aSqlNode
, now that it has been validated.protected boolean
protected boolean
transform
(UnaryOperator<SqlValidator.Config> transform) Returns this SqlValidator, with the same state, applying a transform to the config.usingNames
(SqlJoin join) Returns the set of field names in the join condition specified by USING or implicitly by NATURAL, de-duplicated and in order.Validates an expression tree.void
validateAggregateParams
(SqlCall aggCall, @Nullable SqlNode filter, @Nullable SqlNodeList distinctList, @Nullable SqlNodeList orderList, SqlValidatorScope scope) Validates parameters for aggregate function.void
validateCall
(SqlCall call, SqlValidatorScope scope) Validates a call to an operator.void
validateDataType
(SqlDataTypeSpec dataType) Validates a data type expression.void
validateDelete
(SqlDelete call) Validates a DELETE statement.void
validateDynamicParam
(SqlDynamicParam dynamicParam) Validates a dynamic parameter.protected void
validateFeature
(Feature feature, SqlParserPos context) Validates that a particular feature is enabled.protected void
validateFrom
(SqlNode node, RelDataType targetRowType, SqlValidatorScope scope) Validates the FROM clause of a query, or (recursively) a child node of the FROM clause: AS, OVER, JOIN, VALUES, or sub-query.protected void
validateGroupClause
(SqlSelect select) Validates the GROUP BY clause of a SELECT statement.protected void
validateHavingClause
(SqlSelect select) void
validateIdentifier
(SqlIdentifier id, SqlValidatorScope scope) Resolves an identifier to a fully-qualified name.void
validateInsert
(SqlInsert insert) Validates an INSERT statement.void
validateIntervalQualifier
(SqlIntervalQualifier qualifier) Validates aSqlIntervalQualifier
.protected void
validateJoin
(SqlJoin join, SqlValidatorScope scope) void
validateLambda
(SqlLambda lambdaExpr) Validates a lambda expression.void
validateLiteral
(SqlLiteral literal) Validates a literal.void
Validates a MATCH_RECOGNIZE clause.void
validateMerge
(SqlMerge call) Validates a MERGE statement.boolean
validateModality
(SqlSelect select, SqlModality modality, boolean fail) Validates that a query is capable of producing a return of given modality (relational or streaming).protected void
validateNamespace
(SqlValidatorNamespace namespace, RelDataType targetRowType) Validates a namespace.protected void
validateOrderList
(SqlSelect select) Validates the ORDER BY clause of a SELECT statement.protected void
validateOver
(SqlCall call, SqlValidatorScope scope) validateParameterizedExpression
(SqlNode topNode, Map<String, RelDataType> nameToTypeMap) Validates an expression tree.void
validatePivot
(SqlPivot pivot) protected void
validateQualifyClause
(SqlSelect select) void
validateQuery
(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType) Checks that a query is valid.protected void
validateSelect
(SqlSelect select, RelDataType targetRowType) Validates a SELECT statement.protected RelDataType
validateSelectList
(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType) void
validateSequenceValue
(SqlValidatorScope scope, SqlIdentifier id) protected void
validateTableFunction
(SqlCall node, SqlValidatorScope scope, RelDataType targetRowType) validateTimeFrame
(SqlIntervalQualifier qualifier) Validates a time frame.protected void
validateUnnest
(SqlCall call, SqlValidatorScope scope, RelDataType targetRowType) void
validateUnpivot
(SqlUnpivot unpivot) void
validateUpdate
(SqlUpdate call) Validates an UPDATE statement.protected void
validateValues
(SqlCall node, RelDataType targetRowType, SqlValidatorScope scope) Validates a VALUES clause.protected void
validateWhereClause
(SqlSelect select) protected void
validateWhereOrOn
(SqlValidatorScope scope, SqlNode condition, String clause) void
validateWindow
(SqlNode windowOrId, SqlValidatorScope scope, @Nullable SqlCall call) Validates the right-hand side of an OVER expression.protected void
validateWindowClause
(SqlSelect select) void
validateWith
(SqlWith with, SqlValidatorScope scope) void
validateWithItem
(SqlWithItem withItem) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.calcite.sql.validate.SqlValidator
getTypeMappingRule, resolveWindow
-
Field Details
-
TRACER
public static final org.slf4j.Logger TRACER -
UPDATE_SRC_ALIAS
Alias generated for the source table when rewriting UPDATE to MERGE.- See Also:
-
UPDATE_TGT_ALIAS
Alias generated for the target table when rewriting UPDATE to MERGE if no alias was specified by the user.- See Also:
-
UPDATE_ANON_PREFIX
Alias prefix generated for source columns when rewriting UPDATE to MERGE.- See Also:
-
idPositions
MapsSqlParserPos
strings to theSqlIdentifier
identifier objects at these positions. -
scopes
Mapsquery node
objects to theSqlValidatorScope
scope created from them. -
namespaces
-
functionCallStack
Stack of objects that maintain information about function calls. A stack is needed to handle nested function calls. The function call currently being validated is at the top of the stack. -
typeFactory
-
unknownType
-
timeFrameSet
-
callToOperandTypesMap
Provides the data forgetValidatedOperandTypes(SqlCall)
.
-
-
Constructor Details
-
SqlValidatorImpl
protected SqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlValidator.Config config) Creates a validator.- Parameters:
opTab
- Operator tablecatalogReader
- Catalog readertypeFactory
- Type factoryconfig
- Config
-
-
Method Details
-
getConformance
-
getCatalogReader
Description copied from interface:SqlValidator
Returns the catalog reader used by this validator.- Specified by:
getCatalogReader
in interfaceSqlValidator
- Returns:
- catalog reader
-
getOperatorTable
Description copied from interface:SqlValidator
Returns the operator table used by this validator.- Specified by:
getOperatorTable
in interfaceSqlValidator
- Returns:
- operator table
-
getTypeFactory
Description copied from interface:SqlValidator
Returns the type factory used by this validator.- Specified by:
getTypeFactory
in interfaceSqlValidator
- Returns:
- type factory
-
getUnknownType
Description copied from interface:SqlValidator
Returns an object representing the "unknown" type.- Specified by:
getUnknownType
in interfaceSqlValidator
- Returns:
- unknown type
-
getTimeFrameSet
Description copied from interface:SqlValidator
Returns the set of allowed time frames.- Specified by:
getTimeFrameSet
in interfaceSqlValidator
-
expandStar
Description copied from interface:SqlValidator
Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded.- Specified by:
expandStar
in interfaceSqlValidator
- Parameters:
selectList
- Select clause to be expandedselect
- QueryincludeSystemVars
- Whether to include system variables- Returns:
- expanded select clause
-
declareCursor
Description copied from interface:SqlValidator
Declares a SELECT expression as a cursor.- Specified by:
declareCursor
in interfaceSqlValidator
- Parameters:
select
- select expression associated with the cursorparentScope
- scope of the parent query associated with the cursor
-
pushFunctionCall
public void pushFunctionCall()Description copied from interface:SqlValidator
Pushes a new instance of a function call on to a function call stack.- Specified by:
pushFunctionCall
in interfaceSqlValidator
-
popFunctionCall
public void popFunctionCall()Description copied from interface:SqlValidator
Removes the topmost entry from the function call stack.- Specified by:
popFunctionCall
in interfaceSqlValidator
-
getParentCursor
Description copied from interface:SqlValidator
Retrieves the name of the parent cursor referenced by a column list parameter.- Specified by:
getParentCursor
in interfaceSqlValidator
- Parameters:
columnListParamName
- name of the column list parameter- Returns:
- name of the parent cursor
-
usingNames
Returns the set of field names in the join condition specified by USING or implicitly by NATURAL, de-duplicated and in order. -
validate
Description copied from interface:SqlValidator
Validates an expression tree. You can call this method multiple times, but not reentrantly.- Specified by:
validate
in interfaceSqlValidator
- Parameters:
topNode
- top of expression tree to be validated- Returns:
- validated tree (possibly rewritten)
-
lookupHints
Description copied from interface:SqlValidatorWithHints
Looks up completion hints for a syntactically correct SQL statement that has been parsed into an expression tree. (Note this should be called afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)
.- Specified by:
lookupHints
in interfaceSqlValidatorWithHints
- Parameters:
topNode
- top of expression tree in which to lookup completion hintspos
- indicates the position in the sql statement we want to get completion hints for. For example, "select a.ename, b.deptno from sales.emp a join sales.dept b "on a.deptno=b.deptno where empno=1"; setting pos to 'Line 1, Column 17' returns all the possible column names that can be selected from sales.dept table setting pos to 'Line 1, Column 31' returns all the possible table names in 'sales' schema- Returns:
- an array of
SqlMoniker
(sql identifiers) that can fill in at the indicated position
-
lookupQualifiedName
Description copied from interface:SqlValidatorWithHints
Looks up the fully qualified name for aSqlIdentifier
at a given Parser Position in a parsed expression tree Note: call this only afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)
has been called.- Specified by:
lookupQualifiedName
in interfaceSqlValidatorWithHints
- Parameters:
topNode
- top of expression tree in which to lookup the qualified name for the SqlIdentifierpos
- indicates the position of theSqlIdentifier
in the SQL statement we want to get the qualified name for- Returns:
- a string of the fully qualified name of the
SqlIdentifier
if the Parser position represents a validSqlIdentifier
. Else return null
-
lookupNameCompletionHints
public final void lookupNameCompletionHints(SqlValidatorScope scope, List<String> names, SqlParserPos pos, Collection<SqlMoniker> hintList) Populates a list of all the valid alternatives for an identifier.- Parameters:
scope
- Validation scopenames
- Components of the identifierpos
- positionhintList
- a list of valid options
-
validateParameterizedExpression
public SqlNode validateParameterizedExpression(SqlNode topNode, Map<String, RelDataType> nameToTypeMap) Description copied from interface:SqlValidator
Validates an expression tree. You can call this method multiple times, but not reentrantly.- Specified by:
validateParameterizedExpression
in interfaceSqlValidator
- Parameters:
topNode
- top of expression tree to be validatednameToTypeMap
- map of simple name toRelDataType
; used to resolveSqlIdentifier
references- Returns:
- validated tree (possibly rewritten)
-
validateQuery
Description copied from interface:SqlValidator
Checks that a query is valid.Valid queries include:
SELECT
statement,- set operation (
UNION
,INTERSECT
,EXCEPT
) - identifier (e.g. representing use of a table in a FROM clause)
- query aliased with the
AS
operator
- Specified by:
validateQuery
in interfaceSqlValidator
- Parameters:
node
- Query nodescope
- Scope in which the query occurstargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
validateNamespace
Validates a namespace.- Parameters:
namespace
- NamespacetargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
getEmptyScope
Description copied from interface:SqlValidator
Returns a scope that cannot see anything.- Specified by:
getEmptyScope
in interfaceSqlValidator
-
getCursorScope
-
getWhereScope
Description copied from interface:SqlValidator
Returns the scope that expressions in the WHERE and GROUP BY clause of this query should use. This scope consists of the tables in the FROM clause, and the enclosing scope.- Specified by:
getWhereScope
in interfaceSqlValidator
- Parameters:
select
- Query- Returns:
- naming scope of WHERE clause
-
getSelectScope
Description copied from interface:SqlValidator
Returns the appropriate scope for validating a particular clause of a SELECT statement.Consider
SELECT * FROM foo WHERE EXISTS ( SELECT deptno AS x FROM emp JOIN dept ON emp.deptno = dept.deptno WHERE emp.deptno = 5 GROUP BY deptno ORDER BY x)
What objects can be seen in each part of the sub-query?
- In FROM (
SqlValidator.getFromScope(org.apache.calcite.sql.SqlSelect)
, you can only see 'foo'. - In WHERE (
SqlValidator.getWhereScope(org.apache.calcite.sql.SqlSelect)
), GROUP BY (SqlValidator.getGroupScope(org.apache.calcite.sql.SqlSelect)
), SELECT (getSelectScope
), and the ON clause of the JOIN (SqlValidator.getJoinScope(org.apache.calcite.sql.SqlNode)
) you can see 'emp', 'dept', and 'foo'. - In ORDER BY (
SqlValidator.getOrderScope(org.apache.calcite.sql.SqlSelect)
), you can see the column alias 'x'; and tables 'emp', 'dept', and 'foo'.
- Specified by:
getSelectScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for SELECT statement
- In FROM (
-
getMeasureScope
- Specified by:
getMeasureScope
in interfaceSqlValidator
-
getRawSelectScope
Description copied from interface:SqlValidator
Returns the scope for resolving the SELECT, GROUP BY and HAVING clauses. Always aSelectScope
; if this is an aggregation query, theAggregatingScope
is stripped away.- Specified by:
getRawSelectScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for SELECT statement, sans any aggregating scope
-
getHavingScope
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the HAVING clause of a query.- Specified by:
getHavingScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for HAVING clause
-
getGroupScope
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the GROUP BY clause of a query.- Specified by:
getGroupScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for GROUP BY clause
-
getFromScope
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the FROM clause of a query.- Specified by:
getFromScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for FROM clause
-
getOrderScope
Description copied from interface:SqlValidator
Returns the scope that expressions in the SELECT and HAVING clause of this query should use. This scope consists of the FROM clause and the enclosing scope. If the query is aggregating, only columns in the GROUP BY clause may be used.- Specified by:
getOrderScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for ORDER BY clause
-
getMatchRecognizeScope
Description copied from interface:SqlValidator
Returns a scope match recognize clause.- Specified by:
getMatchRecognizeScope
in interfaceSqlValidator
- Parameters:
node
- Match recognize- Returns:
- naming scope for Match recognize clause
-
getLambdaScope
Description copied from interface:SqlValidator
Returns the lambda expression scope.- Specified by:
getLambdaScope
in interfaceSqlValidator
- Parameters:
node
- Lambda expression- Returns:
- naming scope for lambda expression
-
getJoinScope
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the ON and USING sections of a JOIN clause.- Specified by:
getJoinScope
in interfaceSqlValidator
- Parameters:
node
- The item in the FROM clause which contains the ON or USING expression- Returns:
- naming scope for JOIN clause
- See Also:
-
getOverScope
Description copied from interface:SqlValidator
Returns the scope of an OVER or VALUES node.- Specified by:
getOverScope
in interfaceSqlValidator
- Parameters:
node
- Node- Returns:
- Scope
-
getWithScope
- Specified by:
getWithScope
in interfaceSqlValidator
-
getNamespace
Description copied from interface:SqlValidator
Finds the namespace corresponding to a given node.For example, in the query
SELECT * FROM (SELECT * FROM t), t1 AS alias
, the both items in the FROM clause have a corresponding namespace.- Specified by:
getNamespace
in interfaceSqlValidator
- Parameters:
node
- Parse tree node- Returns:
- namespace of node
-
performUnconditionalRewrites
Performs expression rewrites which are always used unconditionally. These rewrites massage the expression tree into a standard form so that the rest of the validation logic can be simpler.Returns null if and only if the original expression is null.
- Parameters:
node
- expression to be rewrittenunderFrom
- whether node appears directly under a FROM clause- Returns:
- rewritten expression, or null if the original expression is null
-
getSelfJoinExprForUpdate
Allows a subclass to provide information about how to convert an UPDATE into a MERGE via self-join. If this method returns null, then no such conversion takes place. Otherwise, this method should return a suitable unique identifier expression for the given table.- Parameters:
table
- identifier for table being updatedalias
- alias to use for qualifying columns in expression, or null for unqualified references; if this is equal to "SYS$SRC", then column references have been anonymized to "SYS$ANONx", where x is the 1-based column number.- Returns:
- expression for unique identifier, or null to prevent conversion
-
createSourceSelectForUpdate
Creates the SELECT statement that putatively feeds rows into an UPDATE statement to be updated.- Parameters:
call
- Call to the UPDATE operator- Returns:
- select statement
-
createSourceSelectForDelete
Creates the SELECT statement that putatively feeds rows into a DELETE statement to be deleted.- Parameters:
call
- Call to the DELETE operator- Returns:
- select statement
-
getValidatedNodeType
Description copied from interface:SqlValidator
Returns the type assigned to a node by validation.- Specified by:
getValidatedNodeType
in interfaceSqlValidator
- Parameters:
node
- the node of interest- Returns:
- validated type, never null
-
getValidatedNodeTypeIfKnown
Description copied from interface:SqlValidator
Returns the type assigned to a node by validation, or null if unknown. This allows for queries against nodes such as aliases, which have no type of their own. If you want to assert that the node of interest must have a type, useSqlValidator.getValidatedNodeType(org.apache.calcite.sql.SqlNode)
instead.- Specified by:
getValidatedNodeTypeIfKnown
in interfaceSqlValidator
- Parameters:
node
- the node of interest- Returns:
- validated type, or null if unknown or not applicable
-
getValidatedOperandTypes
Description copied from interface:SqlValidator
Returns the types of a call's operands.Returns null if the call has not been validated, or if the operands' types do not differ from their types as expressions.
This method is most useful when some of the operands are of type ANY, or if they need to be coerced to be consistent with other operands, or with the needs of the function.
- Specified by:
getValidatedOperandTypes
in interfaceSqlValidator
- Parameters:
call
- Call- Returns:
- List of operands' types, or null if not known or 'obvious'
-
setValidatedNodeType
Saves the type of aSqlNode
, now that it has been validated.Unlike the base class method, this method is not deprecated. It is available from within Calcite, but is not part of the public API.
- Specified by:
setValidatedNodeType
in interfaceSqlValidator
- Parameters:
node
- A SQL parse tree node, never nulltype
- Its type; must not be null
-
removeValidatedNodeType
Description copied from interface:SqlValidator
Removes a node from the set of validated nodes.- Specified by:
removeValidatedNodeType
in interfaceSqlValidator
- Parameters:
node
- node to be removed
-
makeNullaryCall
Description copied from interface:SqlValidator
If an identifier is a legitimate call to a function that has no arguments and requires no parentheses (for example "CURRENT_USER"), returns a call to that function, otherwise returns null.- Specified by:
makeNullaryCall
in interfaceSqlValidator
-
deriveType
Description copied from interface:SqlValidator
Derives the type of a node in a given scope. If the type has already been inferred, returns the previous type.- Specified by:
deriveType
in interfaceSqlValidator
- Parameters:
scope
- Syntactic scopeexpr
- Parse tree node- Returns:
- Type of the SqlNode. Should never return
NULL
-
deriveConstructorType
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes) Description copied from interface:SqlValidator
Derives the type of a constructor.- Specified by:
deriveConstructorType
in interfaceSqlValidator
- Parameters:
scope
- Scopecall
- CallunresolvedConstructor
- TODOresolvedConstructor
- TODOargTypes
- Types of arguments- Returns:
- Resolved type of constructor
-
handleUnresolvedFunction
public CalciteException handleUnresolvedFunction(SqlCall call, SqlOperator unresolvedFunction, List<RelDataType> argTypes, @Nullable List<String> argNames) Description copied from interface:SqlValidator
Handles a call to a function which cannot be resolved. Returns an appropriately descriptive error, which caller must throw.- Specified by:
handleUnresolvedFunction
in interfaceSqlValidator
- Parameters:
call
- CallunresolvedFunction
- Overloaded function which is the target of the callargTypes
- Types of argumentsargNames
- Names of arguments, or null if call by position
-
inferUnknownTypes
-
addToSelectList
protected void addToSelectList(List<SqlNode> list, Set<String> aliases, List<Map.Entry<String, RelDataType>> fieldList, SqlNode exp, SelectScope scope, boolean includeSystemVars) Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list. -
deriveAlias
Description copied from interface:SqlValidator
Derives an alias for an expression. If no alias can be derived, returns null ifordinal
is less than zero, otherwise generates an aliasEXPR$ordinal
.- Specified by:
deriveAlias
in interfaceSqlValidator
- Parameters:
node
- Expressionordinal
- Ordinal of expression- Returns:
- derived alias, or null if no alias can be derived and ordinal is less than zero
-
shouldAllowIntermediateOrderBy
protected boolean shouldAllowIntermediateOrderBy() -
createMatchRecognizeNameSpace
protected MatchRecognizeNamespace createMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode) -
createPivotNameSpace
-
createUnpivotNameSpace
-
registerNamespace
protected void registerNamespace(@Nullable SqlValidatorScope usingScope, @Nullable String alias, SqlValidatorNamespace ns, boolean forceNullable) Registers a new namespace, and adds it as a child of its parent scope. Derived class can override this method to tinker with namespaces as they are created.- Parameters:
usingScope
- Parent scope (which will want to look for things in this namespace)alias
- Alias by which parent will refer to this namespacens
- NamespaceforceNullable
- Whether to force the type of namespace to be nullable
-
shouldAllowOverRelation
protected boolean shouldAllowOverRelation() -
createSelectNamespace
Creates a namespace for aSELECT
node. Derived class may override this factory method.- Parameters:
select
- Select nodeenclosingNode
- Enclosing node- Returns:
- Select namespace
-
createSetopNamespace
Creates a namespace for a set operation (UNION
,INTERSECT
, orEXCEPT
). Derived class may override this factory method.- Parameters:
call
- Call to set operationenclosingNode
- Enclosing node- Returns:
- Set operation namespace
-
registerQuery
protected void registerQuery(SqlValidatorScope parentScope, @Nullable SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, @Nullable String alias, boolean forceNullable) Registers a query in a parent scope.- Parameters:
parentScope
- Parent scope which this scope turns to in order to resolve objectsusingScope
- Scope whose child list this scope should add itself tonode
- Query nodealias
- Name of this query within its parent. Must be specified if usingScope != null
-
isAggregate
Description copied from interface:SqlValidator
Returns whether a SELECT statement is an aggregation. Criteria are: (1) contains GROUP BY, or (2) contains HAVING, or (3) SELECT or ORDER BY clause contains aggregate functions. (Windowed aggregate functions, such asSUM(x) OVER w
, don't count.)- Specified by:
isAggregate
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- whether SELECT statement is an aggregation
-
isNestedAggregateWindow
-
isOverAggregateWindow
-
getAggregate
Returns the parse tree node (GROUP BY, HAVING, or an aggregate function call) that causesselect
to be an aggregate query, or null if it is not an aggregate query.The node is useful context for error messages, but you cannot assume that the node is the only aggregate function.
-
isAggregate
Deprecated.Description copied from interface:SqlValidator
Returns whether a select list expression is an aggregate function.- Specified by:
isAggregate
in interfaceSqlValidator
- Parameters:
selectNode
- Expression in SELECT clause- Returns:
- whether expression is an aggregate function
-
validateIdentifier
Description copied from interface:SqlValidator
Resolves an identifier to a fully-qualified name.- Specified by:
validateIdentifier
in interfaceSqlValidator
- Parameters:
id
- Identifierscope
- Naming scope
-
validateLiteral
Description copied from interface:SqlValidator
Validates a literal.- Specified by:
validateLiteral
in interfaceSqlValidator
- Parameters:
literal
- Literal
-
validateIntervalQualifier
Description copied from interface:SqlValidator
Validates aSqlIntervalQualifier
.- Specified by:
validateIntervalQualifier
in interfaceSqlValidator
- Parameters:
qualifier
- Interval qualifier
-
validateTimeFrame
Description copied from interface:SqlValidator
Validates a time frame.A time frame is either a built-in time frame based on a time unit such as
TimeUnitRange.HOUR
, or is a custom time frame represented by a name inSqlIntervalQualifier.timeFrameName
. A custom time frame is validated againstSqlValidator.getTimeFrameSet()
.Returns a time frame, or throws.
- Specified by:
validateTimeFrame
in interfaceSqlValidator
-
validateFrom
Validates the FROM clause of a query, or (recursively) a child node of the FROM clause: AS, OVER, JOIN, VALUES, or sub-query.- Parameters:
node
- Node in FROM clause, typically a table or derived tabletargetRowType
- Desired row type of this expression, orunknownType
if not fussy. Must not be null.scope
- Scope
-
validateTableFunction
protected void validateTableFunction(SqlCall node, SqlValidatorScope scope, RelDataType targetRowType) -
validateOver
-
validateUnnest
-
validateJoin
-
validateSelect
Validates a SELECT statement.- Parameters:
select
- Select statementtargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
validateModality
Description copied from interface:SqlValidator
Validates that a query is capable of producing a return of given modality (relational or streaming).- Specified by:
validateModality
in interfaceSqlValidator
- Parameters:
select
- Querymodality
- Modality (streaming or relational)fail
- Whether to throw a user error if does not support required modality- Returns:
- whether query supports the given modality
-
validateWindowClause
-
validateQualifyClause
-
validateWith
- Specified by:
validateWith
in interfaceSqlValidator
-
validateWithItem
- Specified by:
validateWithItem
in interfaceSqlValidator
-
validateSequenceValue
- Specified by:
validateSequenceValue
in interfaceSqlValidator
-
getTypeCoercion
Description copied from interface:SqlValidator
Get the type coercion instance.- Specified by:
getTypeCoercion
in interfaceSqlValidator
-
config
Description copied from interface:SqlValidator
Returns the config of the validator.- Specified by:
config
in interfaceSqlValidator
-
transform
Description copied from interface:SqlValidator
Returns this SqlValidator, with the same state, applying a transform to the config.This is mainly used for tests, otherwise constructs a
SqlValidator.Config
directly through the constructor.- Specified by:
transform
in interfaceSqlValidator
-
validateOrderList
Validates the ORDER BY clause of a SELECT statement.- Parameters:
select
- Select statement
-
expandOrderExpr
Description copied from interface:SqlValidator
Expands an expression in the ORDER BY clause into an expression with the same semantics as expressions in the SELECT clause.This is made necessary by a couple of dialect 'features':
- ordinal expressions: In "SELECT x, y FROM t ORDER BY 2", the expression "2" is shorthand for the 2nd item in the select clause, namely "y".
- alias references: In "SELECT x AS a, y FROM t ORDER BY a", the expression "a" is shorthand for the item in the select clause whose alias is "a"
- Specified by:
expandOrderExpr
in interfaceSqlValidator
- Parameters:
select
- Select statement which contains ORDER BYorderExpr
- Expression in the ORDER BY clause.- Returns:
- Expression translated into SELECT clause semantics
-
validateGroupClause
Validates the GROUP BY clause of a SELECT statement. This method is called even if no GROUP BY clause is present. -
validateWhereClause
-
validateWhereOrOn
-
validateHavingClause
-
validateSelectList
protected RelDataType validateSelectList(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType) -
createTargetRowType
protected RelDataType createTargetRowType(SqlValidatorTable table, @Nullable SqlNodeList targetColumnList, boolean append, @Nullable SqlIdentifier targetTableAlias) Derives a row-type for INSERT and UPDATE operations.- Parameters:
table
- Target table for INSERT/UPDATEtargetColumnList
- List of target columns, or null if not specifiedappend
- Whether to append fields to those inbaseRowType
targetTableAlias
- Target table alias, or null if not specified- Returns:
- Rowtype
-
validateInsert
Description copied from interface:SqlValidator
Validates an INSERT statement.- Specified by:
validateInsert
in interfaceSqlValidator
- Parameters:
insert
- INSERT statement
-
getLogicalTargetRowType
-
getLogicalSourceRowType
-
checkTypeAssignment
protected void checkTypeAssignment(@Nullable SqlValidatorScope sourceScope, SqlValidatorTable table, RelDataType sourceRowType, RelDataType targetRowType, SqlNode query) Checks the type assignment of an INSERT or UPDATE query.Skip the virtual columns(can not insert into) type assignment check if the source fields count equals with the real target table fields count, see how #checkFieldCount was used.
- Parameters:
sourceScope
- Scope of query source which is used to infer node typetable
- Target tablesourceRowType
- Source row typetargetRowType
- Target row type, it should either contain all the virtual columns (can not insert into) or exclude all the virtual columnsquery
- The query
-
validateDelete
Description copied from interface:SqlValidator
Validates a DELETE statement.- Specified by:
validateDelete
in interfaceSqlValidator
- Parameters:
call
- DELETE statement
-
validateUpdate
Description copied from interface:SqlValidator
Validates an UPDATE statement.- Specified by:
validateUpdate
in interfaceSqlValidator
- Parameters:
call
- UPDATE statement
-
validateMerge
Description copied from interface:SqlValidator
Validates a MERGE statement.- Specified by:
validateMerge
in interfaceSqlValidator
- Parameters:
call
- MERGE statement
-
validateValues
Validates a VALUES clause.- Parameters:
node
- Values clausetargetRowType
- Row type which expression must conform toscope
- Scope within which clause occurs
-
validateDataType
Description copied from interface:SqlValidator
Validates a data type expression.- Specified by:
validateDataType
in interfaceSqlValidator
- Parameters:
dataType
- Data type
-
validateDynamicParam
Description copied from interface:SqlValidator
Validates a dynamic parameter.- Specified by:
validateDynamicParam
in interfaceSqlValidator
- Parameters:
dynamicParam
- Dynamic parameter
-
getValidationErrorFunction
public org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationErrorFunction getValidationErrorFunction() -
newValidationError
public CalciteContextException newValidationError(SqlNode node, org.apache.calcite.runtime.Resources.ExInst<SqlValidatorException> e) Description copied from interface:SqlValidator
Adds "line x, column y" context to a validator exception.Note that the input exception is checked (it derives from
Exception
) and the output exception is unchecked (it derives fromRuntimeException
). This is intentional -- it should remind code authors to provide context for their validation errors.- Specified by:
newValidationError
in interfaceSqlValidator
- Parameters:
node
- The place where the exception occurred, not nulle
- The validation error- Returns:
- Exception containing positional information, never null
-
getWindowByName
-
resolveWindow
Description copied from interface:SqlValidator
Converts a window specification or window name into a fully-resolved window specification. For example, inSELECT sum(x) OVER (PARTITION BY x ORDER BY y), sum(y) OVER w1, sum(z) OVER (w ORDER BY y) FROM t WINDOW w AS (PARTITION BY x)
all aggregations have the same resolved window specification(PARTITION BY x ORDER BY y)
.- Specified by:
resolveWindow
in interfaceSqlValidator
- Parameters:
windowOrRef
- Either the name of a window (aSqlIdentifier
) or a window specification (aSqlWindow
).scope
- Scope in which to resolve window names- Returns:
- A window
-
getOriginal
-
setOriginal
-
validateWindow
Description copied from interface:SqlValidator
Validates the right-hand side of an OVER expression. It might be either anidentifier
referencing a window, or aninline window specification
.- Specified by:
validateWindow
in interfaceSqlValidator
- Parameters:
windowOrId
- SqlNode that can be either SqlWindow with all the components of a window spec or a SqlIdentifier with the name of a window spec.scope
- Naming scopecall
- the SqlNode if a function call if the window is attached to one.
-
validateLambda
Description copied from interface:SqlValidator
Validates a lambda expression. lambda expression will be validated twice during the validation process. The first time is validate lambda expression namespace, the second time is when validating higher order function operands type check.- Specified by:
validateLambda
in interfaceSqlValidator
- Parameters:
lambdaExpr
- Lambda expression
-
validateMatchRecognize
Description copied from interface:SqlValidator
Validates a MATCH_RECOGNIZE clause.- Specified by:
validateMatchRecognize
in interfaceSqlValidator
- Parameters:
call
- MATCH_RECOGNIZE clause
-
validatePivot
-
validateUnpivot
-
validateAggregateParams
public void validateAggregateParams(SqlCall aggCall, @Nullable SqlNode filter, @Nullable SqlNodeList distinctList, @Nullable SqlNodeList orderList, SqlValidatorScope scope) Description copied from interface:SqlValidator
Validates parameters for aggregate function.- Specified by:
validateAggregateParams
in interfaceSqlValidator
- Parameters:
aggCall
- Call to aggregate functionfilter
- Filter (FILTER (WHERE)
clause), or nulldistinctList
- Distinct specification (WITHIN DISTINCT
clause), or nullorderList
- Ordering specification (WITHIN GROUP
clause), or nullscope
- Syntactic scope
-
validateCall
Description copied from interface:SqlValidator
Validates a call to an operator.- Specified by:
validateCall
in interfaceSqlValidator
- Parameters:
call
- Operator callscope
- Naming scope
-
validateFeature
Validates that a particular feature is enabled. By default, all features are enabled; subclasses may override this method to be more discriminating.- Parameters:
feature
- feature being used, represented as a resource instancecontext
- parser position context for error reporting, or null if
-
resolveLiteral
Description copied from interface:SqlValidator
Resolves a literal.Usually returns the literal unchanged, but if the literal is of type
SqlTypeName.UNKNOWN
looks up its type and converts to the appropriate literal subclass.- Specified by:
resolveLiteral
in interfaceSqlValidator
-
expandSelectExpr
-
expand
Description copied from interface:SqlValidator
Expands an expression.- Specified by:
expand
in interfaceSqlValidator
- Parameters:
expr
- Expressionscope
- Scope- Returns:
- Expanded expression
-
extendedExpandGroupBy
-
isSystemField
Description copied from interface:SqlValidator
Returns whether a field is a system field. Such fields may have particular properties such as sortedness and nullability.In the default implementation, always returns
false
.- Specified by:
isSystemField
in interfaceSqlValidator
- Parameters:
field
- Field- Returns:
- whether field is a system field
-
getFieldOrigins
Description copied from interface:SqlValidator
Returns a description of how each field in the row type maps to a catalog, schema, table and column in the schema.The returned list is never null, and has one element for each field in the row type. Each element is a list of four elements (catalog, schema, table, column), or may be null if the column is an expression.
- Specified by:
getFieldOrigins
in interfaceSqlValidator
- Parameters:
sqlQuery
- Query- Returns:
- Description of how each field in the row type maps to a schema object
-
getParameterRowType
Description copied from interface:SqlValidator
Returns a record type that contains the name and type of each parameter. Returns a record type with no fields if there are no parameters.- Specified by:
getParameterRowType
in interfaceSqlValidator
- Parameters:
sqlQuery
- Query- Returns:
- Record type
-