Class SqlValidatorImpl
- All Implemented Interfaces:
SqlValidator,SqlValidatorWithHints
- Direct Known Subclasses:
CalciteSqlValidator,ContextSqlValidator,SqlAdvisorValidator
SqlValidator.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCommon base class for DML statement namespaces.protected static classUtility object used to maintain information about the parameters in a function call.protected static classInformation about an identifier in a particular scope.static enumValidation status.Nested classes/interfaces inherited from interface org.apache.calcite.sql.validate.SqlValidator
SqlValidator.Config -
Field Summary
FieldsModifier 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> MapsSqlParserPosstrings to theSqlIdentifieridentifier objects at these positions.protected final IdentityHashMap<SqlNode,SqlValidatorNamespace> protected final IdentityHashMap<SqlNode,SqlValidatorScope> Mapsquery nodeobjects to theSqlValidatorScopescope created from them.protected final TimeFrameSetstatic final org.slf4j.Loggerprotected final RelDataTypeFactoryprotected final RelDataTypestatic final StringAlias prefix generated for source columns when rewriting UPDATE to MERGE.static final StringAlias generated for the source table when rewriting UPDATE to MERGE.static final StringAlias generated for the target table when rewriting UPDATE to MERGE if no alias was specified by the user. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlValidator.Config config) Creates a validator. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddToSelectList(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 voidcheckTypeAssignment(@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 MatchRecognizeNamespacecreateMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode) protected PivotNamespacecreatePivotNameSpace(SqlPivot call, SqlNode enclosingNode) protected SelectNamespacecreateSelectNamespace(SqlSelect select, SqlNode enclosingNode) Creates a namespace for aSELECTnode.protected SetopNamespacecreateSetopNamespace(SqlCall call, SqlNode enclosingNode) Creates a namespace for a set operation (UNION,INTERSECT, orEXCEPT).protected SqlSelectCreates the SELECT statement that putatively feeds rows into a DELETE statement to be deleted.protected SqlSelectCreates the SELECT statement that putatively feeds rows into an UPDATE statement to be updated.protected RelDataTypecreateTargetRowType(SqlValidatorTable table, @Nullable SqlNodeList targetColumnList, boolean append, @Nullable SqlIdentifier targetTableAlias) Derives a row-type for INSERT and UPDATE operations.protected UnpivotNamespacecreateUnpivotNameSpace(SqlUnpivot call, SqlNode enclosingNode) voiddeclareCursor(SqlSelect select, SqlValidatorScope parentScope) Declares a SELECT expression as a cursor.@Nullable StringderiveAlias(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, Map<String, SqlNode> expansions) 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 SqlNodegetAggregate(SqlSelect select) Returns the parse tree node (GROUP BY, HAVING, or an aggregate function call) that causesselectto 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 RelDataTypegetLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert) protected RelDataTypegetLogicalTargetRowType(RelDataType targetRowType, SqlInsert insert) Returns a scope match recognize clause.getMeasureScope(SqlSelect select) @Nullable SqlValidatorNamespacegetNamespace(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 StringgetParentCursor(String columnListParamName) Retrieves the name of the parent cursor referenced by a column list parameter.@Nullable SelectScopegetRawSelectScope(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 SqlNodegetSelfJoinExprForUpdate(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 RelDataTypeReturns 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.ValidationErrorFunctiongetWhereScope(SqlSelect select) Returns the scope that expressions in the WHERE and GROUP BY clause of this query should use.protected SqlWindowgetWindowByName(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 voidinferUnknownTypes(RelDataType inferredType, SqlValidatorScope scope, SqlNode node) booleanisAggregate(SqlNode selectNode) Deprecated.booleanisAggregate(SqlSelect select) Returns whether a SELECT statement is an aggregation.protected booleanprotected booleanisOverAggregateWindow(SqlNode node) booleanisSystemField(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 voidlookupNameCompletionHints(SqlValidatorScope scope, List<String> names, SqlParserPos pos, Collection<SqlMoniker> hintList) Populates a list of all the valid alternatives for an identifier.@Nullable SqlMonikerlookupQualifiedName(SqlNode topNode, SqlParserPos pos) Looks up the fully qualified name for aSqlIdentifierat a given Parser Position in a parsed expression tree Note: call this only afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)has been called.@Nullable SqlCallIf 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 SqlNodeperformUnconditionalRewrites(@PolyNull SqlNode node, boolean underFrom) Performs expression rewrites which are always used unconditionally.voidRemoves the topmost entry from the function call stack.voidPushes a new instance of a function call on to a function call stack.protected voidregisterNamespace(@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 voidregisterQuery(SqlValidatorScope parentScope, @Nullable SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, @Nullable String alias, boolean forceNullable) Registers a query in a parent scope.voidRemoves 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.voidsetOriginal(SqlNode expr, SqlNode original) final voidsetValidatedNodeType(SqlNode node, RelDataType type) Saves the type of aSqlNode, now that it has been validated.protected booleanprotected booleantransform(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.voidvalidateAggregateParams(SqlCall aggCall, @Nullable SqlNode filter, @Nullable SqlNodeList distinctList, @Nullable SqlNodeList orderList, SqlValidatorScope scope) Validates parameters for aggregate function.voidvalidateCall(SqlCall call, SqlValidatorScope scope) Validates a call to an operator.voidvalidateDataType(SqlDataTypeSpec dataType) Validates a data type expression.voidvalidateDelete(SqlDelete call) Validates a DELETE statement.voidvalidateDynamicParam(SqlDynamicParam dynamicParam) Validates a dynamic parameter.protected voidvalidateFeature(Feature feature, SqlParserPos context) Validates that a particular feature is enabled.protected voidvalidateFrom(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 voidvalidateGroupClause(SqlSelect select) Validates the GROUP BY clause of a SELECT statement.protected voidvalidateHavingClause(SqlSelect select) voidvalidateIdentifier(SqlIdentifier id, SqlValidatorScope scope) Resolves an identifier to a fully-qualified name.voidvalidateInsert(SqlInsert insert) Validates an INSERT statement.voidvalidateIntervalQualifier(SqlIntervalQualifier qualifier) Validates aSqlIntervalQualifier.protected voidvalidateJoin(SqlJoin join, SqlValidatorScope scope) voidvalidateLambda(SqlLambda lambdaExpr) Validates a lambda expression.voidvalidateLiteral(SqlLiteral literal) Validates a literal.voidValidates a MATCH_RECOGNIZE clause.voidvalidateMerge(SqlMerge call) Validates a MERGE statement.booleanvalidateModality(SqlSelect select, SqlModality modality, boolean fail) Validates that a query is capable of producing a return of given modality (relational or streaming).protected voidvalidateMustFilterRequirements(SqlSelect select, SelectNamespace ns) protected voidvalidateNamespace(SqlValidatorNamespace namespace, RelDataType targetRowType) Validates a namespace.protected voidvalidateOrderList(SqlSelect select) Validates the ORDER BY clause of a SELECT statement.protected voidvalidateOver(SqlCall call, SqlValidatorScope scope) validateParameterizedExpression(SqlNode topNode, Map<String, RelDataType> nameToTypeMap) Validates an expression tree.voidvalidatePivot(SqlPivot pivot) protected voidvalidateQualifyClause(SqlSelect select) voidvalidateQuery(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType) Checks that a query is valid.protected voidvalidateSelect(SqlSelect select, RelDataType targetRowType) Validates a SELECT statement.protected RelDataTypevalidateSelectList(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType) voidvalidateSequenceValue(SqlValidatorScope scope, SqlIdentifier id) protected voidvalidateTableFunction(SqlCall node, SqlValidatorScope scope, RelDataType targetRowType) validateTimeFrame(SqlIntervalQualifier qualifier) Validates a time frame.protected voidvalidateUnnest(SqlCall call, SqlValidatorScope scope, RelDataType targetRowType) voidvalidateUnpivot(SqlUnpivot unpivot) voidvalidateUpdate(SqlUpdate call) Validates an UPDATE statement.protected voidvalidateValues(SqlCall node, RelDataType targetRowType, SqlValidatorScope scope) Validates a VALUES clause.protected voidvalidateWhereClause(SqlSelect select) protected voidvalidateWhereOrOn(SqlValidatorScope scope, SqlNode condition, String clause) voidvalidateWindow(SqlNode windowOrId, SqlValidatorScope scope, @Nullable SqlCall call) Validates the right-hand side of an OVER expression.protected voidvalidateWindowClause(SqlSelect select) voidvalidateWith(SqlWith with, SqlValidatorScope scope) voidvalidateWithItem(SqlWithItem withItem) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
MapsSqlParserPosstrings to theSqlIdentifieridentifier objects at these positions. -
scopes
Mapsquery nodeobjects to theSqlValidatorScopescope 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:SqlValidatorReturns the catalog reader used by this validator.- Specified by:
getCatalogReaderin interfaceSqlValidator- Returns:
- catalog reader
-
getOperatorTable
Description copied from interface:SqlValidatorReturns the operator table used by this validator.- Specified by:
getOperatorTablein interfaceSqlValidator- Returns:
- operator table
-
getTypeFactory
Description copied from interface:SqlValidatorReturns the type factory used by this validator.- Specified by:
getTypeFactoryin interfaceSqlValidator- Returns:
- type factory
-
getUnknownType
Description copied from interface:SqlValidatorReturns an object representing the "unknown" type.- Specified by:
getUnknownTypein interfaceSqlValidator- Returns:
- unknown type
-
getTimeFrameSet
Description copied from interface:SqlValidatorReturns the set of allowed time frames.- Specified by:
getTimeFrameSetin interfaceSqlValidator
-
expandStar
Description copied from interface:SqlValidatorReturns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded.- Specified by:
expandStarin interfaceSqlValidator- Parameters:
selectList- Select clause to be expandedselect- QueryincludeSystemVars- Whether to include system variables- Returns:
- expanded select clause
-
declareCursor
Description copied from interface:SqlValidatorDeclares a SELECT expression as a cursor.- Specified by:
declareCursorin 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:SqlValidatorPushes a new instance of a function call on to a function call stack.- Specified by:
pushFunctionCallin interfaceSqlValidator
-
popFunctionCall
public void popFunctionCall()Description copied from interface:SqlValidatorRemoves the topmost entry from the function call stack.- Specified by:
popFunctionCallin interfaceSqlValidator
-
getParentCursor
Description copied from interface:SqlValidatorRetrieves the name of the parent cursor referenced by a column list parameter.- Specified by:
getParentCursorin 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:SqlValidatorValidates an expression tree. You can call this method multiple times, but not reentrantly.- Specified by:
validatein interfaceSqlValidator- Parameters:
topNode- top of expression tree to be validated- Returns:
- validated tree (possibly rewritten)
-
lookupHints
Description copied from interface:SqlValidatorWithHintsLooks 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:
lookupHintsin 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:SqlValidatorWithHintsLooks up the fully qualified name for aSqlIdentifierat 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:
lookupQualifiedNamein interfaceSqlValidatorWithHints- Parameters:
topNode- top of expression tree in which to lookup the qualified name for the SqlIdentifierpos- indicates the position of theSqlIdentifierin the SQL statement we want to get the qualified name for- Returns:
- a string of the fully qualified name of the
SqlIdentifierif 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:SqlValidatorValidates an expression tree. You can call this method multiple times, but not reentrantly.- Specified by:
validateParameterizedExpressionin interfaceSqlValidator- Parameters:
topNode- top of expression tree to be validatednameToTypeMap- map of simple name toRelDataType; used to resolveSqlIdentifierreferences- Returns:
- validated tree (possibly rewritten)
-
validateQuery
Description copied from interface:SqlValidatorChecks that a query is valid.Valid queries include:
SELECTstatement,- set operation (
UNION,INTERSECT,EXCEPT) - identifier (e.g. representing use of a table in a FROM clause)
- query aliased with the
ASoperator
- Specified by:
validateQueryin 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:SqlValidatorReturns a scope that cannot see anything.- Specified by:
getEmptyScopein interfaceSqlValidator
-
getCursorScope
-
getWhereScope
Description copied from interface:SqlValidatorReturns 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:
getWhereScopein interfaceSqlValidator- Parameters:
select- Query- Returns:
- naming scope of WHERE clause
-
getSelectScope
Description copied from interface:SqlValidatorReturns 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:
getSelectScopein interfaceSqlValidator- Parameters:
select- SELECT statement- Returns:
- naming scope for SELECT statement
- In FROM (
-
getMeasureScope
- Specified by:
getMeasureScopein interfaceSqlValidator
-
getRawSelectScope
Description copied from interface:SqlValidatorReturns the scope for resolving the SELECT, GROUP BY and HAVING clauses. Always aSelectScope; if this is an aggregation query, theAggregatingScopeis stripped away.- Specified by:
getRawSelectScopein interfaceSqlValidator- Parameters:
select- SELECT statement- Returns:
- naming scope for SELECT statement, sans any aggregating scope
-
getHavingScope
Description copied from interface:SqlValidatorReturns a scope containing the objects visible from the HAVING clause of a query.- Specified by:
getHavingScopein interfaceSqlValidator- Parameters:
select- SELECT statement- Returns:
- naming scope for HAVING clause
-
getGroupScope
Description copied from interface:SqlValidatorReturns a scope containing the objects visible from the GROUP BY clause of a query.- Specified by:
getGroupScopein interfaceSqlValidator- Parameters:
select- SELECT statement- Returns:
- naming scope for GROUP BY clause
-
getFromScope
Description copied from interface:SqlValidatorReturns a scope containing the objects visible from the FROM clause of a query.- Specified by:
getFromScopein interfaceSqlValidator- Parameters:
select- SELECT statement- Returns:
- naming scope for FROM clause
-
getOrderScope
Description copied from interface:SqlValidatorReturns 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:
getOrderScopein interfaceSqlValidator- Parameters:
select- SELECT statement- Returns:
- naming scope for ORDER BY clause
-
getMatchRecognizeScope
Description copied from interface:SqlValidatorReturns a scope match recognize clause.- Specified by:
getMatchRecognizeScopein interfaceSqlValidator- Parameters:
node- Match recognize- Returns:
- naming scope for Match recognize clause
-
getLambdaScope
Description copied from interface:SqlValidatorReturns the lambda expression scope.- Specified by:
getLambdaScopein interfaceSqlValidator- Parameters:
node- Lambda expression- Returns:
- naming scope for lambda expression
-
getJoinScope
Description copied from interface:SqlValidatorReturns a scope containing the objects visible from the ON and USING sections of a JOIN clause.- Specified by:
getJoinScopein 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:SqlValidatorReturns the scope of an OVER or VALUES node.- Specified by:
getOverScopein interfaceSqlValidator- Parameters:
node- Node- Returns:
- Scope
-
getWithScope
- Specified by:
getWithScopein interfaceSqlValidator
-
getNamespace
Description copied from interface:SqlValidatorFinds 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:
getNamespacein 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:SqlValidatorReturns the type assigned to a node by validation.- Specified by:
getValidatedNodeTypein interfaceSqlValidator- Parameters:
node- the node of interest- Returns:
- validated type, never null
-
getValidatedNodeTypeIfKnown
Description copied from interface:SqlValidatorReturns 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:
getValidatedNodeTypeIfKnownin interfaceSqlValidator- Parameters:
node- the node of interest- Returns:
- validated type, or null if unknown or not applicable
-
getValidatedOperandTypes
Description copied from interface:SqlValidatorReturns 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:
getValidatedOperandTypesin 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:
setValidatedNodeTypein interfaceSqlValidator- Parameters:
node- A SQL parse tree node, never nulltype- Its type; must not be null
-
removeValidatedNodeType
Description copied from interface:SqlValidatorRemoves a node from the set of validated nodes.- Specified by:
removeValidatedNodeTypein interfaceSqlValidator- Parameters:
node- node to be removed
-
makeNullaryCall
Description copied from interface:SqlValidatorIf 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:
makeNullaryCallin interfaceSqlValidator
-
deriveType
Description copied from interface:SqlValidatorDerives the type of a node in a given scope. If the type has already been inferred, returns the previous type.- Specified by:
deriveTypein 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:SqlValidatorDerives the type of a constructor.- Specified by:
deriveConstructorTypein 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:SqlValidatorHandles a call to a function which cannot be resolved. Returns an appropriately descriptive error, which caller must throw.- Specified by:
handleUnresolvedFunctionin 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:SqlValidatorDerives an alias for an expression. If no alias can be derived, returns null ifordinalis less than zero, otherwise generates an aliasEXPR$ordinal.- Specified by:
deriveAliasin 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 aSELECTnode. 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:SqlValidatorReturns 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:
isAggregatein 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 causesselectto 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:SqlValidatorReturns whether a select list expression is an aggregate function.- Specified by:
isAggregatein interfaceSqlValidator- Parameters:
selectNode- Expression in SELECT clause- Returns:
- whether expression is an aggregate function
-
validateIdentifier
Description copied from interface:SqlValidatorResolves an identifier to a fully-qualified name.- Specified by:
validateIdentifierin interfaceSqlValidator- Parameters:
id- Identifierscope- Naming scope
-
validateLiteral
Description copied from interface:SqlValidatorValidates a literal.- Specified by:
validateLiteralin interfaceSqlValidator- Parameters:
literal- Literal
-
validateIntervalQualifier
Description copied from interface:SqlValidatorValidates aSqlIntervalQualifier.- Specified by:
validateIntervalQualifierin interfaceSqlValidator- Parameters:
qualifier- Interval qualifier
-
validateTimeFrame
Description copied from interface:SqlValidatorValidates 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:
validateTimeFramein 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, orunknownTypeif 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:SqlValidatorValidates that a query is capable of producing a return of given modality (relational or streaming).- Specified by:
validateModalityin 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
-
validateMustFilterRequirements
-
validateWith
- Specified by:
validateWithin interfaceSqlValidator
-
validateWithItem
- Specified by:
validateWithItemin interfaceSqlValidator
-
validateSequenceValue
- Specified by:
validateSequenceValuein interfaceSqlValidator
-
getTypeCoercion
Description copied from interface:SqlValidatorGet the type coercion instance.- Specified by:
getTypeCoercionin interfaceSqlValidator
-
config
Description copied from interface:SqlValidatorReturns the config of the validator.- Specified by:
configin interfaceSqlValidator
-
transform
Description copied from interface:SqlValidatorReturns this SqlValidator, with the same state, applying a transform to the config.This is mainly used for tests, otherwise constructs a
SqlValidator.Configdirectly through the constructor.- Specified by:
transformin interfaceSqlValidator
-
validateOrderList
Validates the ORDER BY clause of a SELECT statement.- Parameters:
select- Select statement
-
expandOrderExpr
Description copied from interface:SqlValidatorExpands 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:
expandOrderExprin 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 inbaseRowTypetargetTableAlias- Target table alias, or null if not specified- Returns:
- Rowtype
-
validateInsert
Description copied from interface:SqlValidatorValidates an INSERT statement.- Specified by:
validateInsertin 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:SqlValidatorValidates a DELETE statement.- Specified by:
validateDeletein interfaceSqlValidator- Parameters:
call- DELETE statement
-
validateUpdate
Description copied from interface:SqlValidatorValidates an UPDATE statement.- Specified by:
validateUpdatein interfaceSqlValidator- Parameters:
call- UPDATE statement
-
validateMerge
Description copied from interface:SqlValidatorValidates a MERGE statement.- Specified by:
validateMergein 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:SqlValidatorValidates a data type expression.- Specified by:
validateDataTypein interfaceSqlValidator- Parameters:
dataType- Data type
-
validateDynamicParam
Description copied from interface:SqlValidatorValidates a dynamic parameter.- Specified by:
validateDynamicParamin 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:SqlValidatorAdds "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:
newValidationErrorin 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:SqlValidatorConverts 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:
resolveWindowin 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:SqlValidatorValidates the right-hand side of an OVER expression. It might be either anidentifierreferencing a window, or aninline window specification.- Specified by:
validateWindowin 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:SqlValidatorValidates 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:
validateLambdain interfaceSqlValidator- Parameters:
lambdaExpr- Lambda expression
-
validateMatchRecognize
Description copied from interface:SqlValidatorValidates a MATCH_RECOGNIZE clause.- Specified by:
validateMatchRecognizein 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:SqlValidatorValidates parameters for aggregate function.- Specified by:
validateAggregateParamsin interfaceSqlValidator- Parameters:
aggCall- Call to aggregate functionfilter- Filter (FILTER (WHERE)clause), or nulldistinctList- Distinct specification (WITHIN DISTINCTclause), or nullorderList- Ordering specification (WITHIN GROUPclause), or nullscope- Syntactic scope
-
validateCall
Description copied from interface:SqlValidatorValidates a call to an operator.- Specified by:
validateCallin 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:SqlValidatorResolves a literal.Usually returns the literal unchanged, but if the literal is of type
SqlTypeName.UNKNOWNlooks up its type and converts to the appropriate literal subclass.- Specified by:
resolveLiteralin interfaceSqlValidator
-
expandSelectExpr
-
expand
Description copied from interface:SqlValidatorExpands an expression.- Specified by:
expandin interfaceSqlValidator- Parameters:
expr- Expressionscope- Scope- Returns:
- Expanded expression
-
extendedExpandGroupBy
-
isSystemField
Description copied from interface:SqlValidatorReturns 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:
isSystemFieldin interfaceSqlValidator- Parameters:
field- Field- Returns:
- whether field is a system field
-
getFieldOrigins
Description copied from interface:SqlValidatorReturns 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:
getFieldOriginsin interfaceSqlValidator- Parameters:
sqlQuery- Query- Returns:
- Description of how each field in the row type maps to a schema object
-
getParameterRowType
Description copied from interface:SqlValidatorReturns 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:
getParameterRowTypein interfaceSqlValidator- Parameters:
sqlQuery- Query- Returns:
- Record type
-