public class SqlValidatorImpl extends Object implements SqlValidatorWithHints
SqlValidator.| Modifier and Type | Class and Description |
|---|---|
static class |
SqlValidatorImpl.DmlNamespace
Common base class for DML statement namespaces.
|
protected static class |
SqlValidatorImpl.FunctionParamInfo
Utility object used to maintain information about the parameters in a
function call.
|
protected static class |
SqlValidatorImpl.IdInfo
Information about an identifier in a particular scope.
|
static class |
SqlValidatorImpl.Status
Validation status.
|
SqlValidator.Config| Modifier and Type | Field and Description |
|---|---|
IdentityHashMap<SqlCall,List<RelDataType>> |
callToOperandTypesMap
Provides the data for
getValidatedOperandTypes(SqlCall). |
protected Deque<SqlValidatorImpl.FunctionParamInfo> |
functionCallStack
Stack of objects that maintain information about function calls.
|
protected Map<String,SqlValidatorImpl.IdInfo> |
idPositions
Maps
SqlParserPos strings to the SqlIdentifier identifier
objects at these positions. |
protected IdentityHashMap<SqlNode,SqlValidatorNamespace> |
namespaces
|
protected IdentityHashMap<SqlNode,SqlValidatorScope> |
scopes
Maps
query node objects to the SqlValidatorScope
scope created from them. |
static org.slf4j.Logger |
TRACER |
protected RelDataTypeFactory |
typeFactory |
protected RelDataType |
unknownType
The type of dynamic parameters until a type is imposed on them.
|
static String |
UPDATE_ANON_PREFIX
Alias prefix generated for source columns when rewriting UPDATE to MERGE.
|
static String |
UPDATE_SRC_ALIAS
Alias generated for the source table when rewriting UPDATE to MERGE.
|
static String |
UPDATE_TGT_ALIAS
Alias generated for the target table when rewriting UPDATE to MERGE if no
alias was specified by the user.
|
| Modifier | Constructor and Description |
|---|---|
protected |
SqlValidatorImpl(SqlOperatorTable opTab,
SqlValidatorCatalogReader catalogReader,
RelDataTypeFactory typeFactory,
SqlValidator.Config config)
Creates a validator.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
protected void |
checkTypeAssignment(@Nullable SqlValidatorScope sourceScope,
SqlValidatorTable table,
RelDataType sourceRowType,
RelDataType targetRowType,
SqlNode query)
Checks the type assignment of an INSERT or UPDATE query.
|
SqlValidator.Config |
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 a
SELECT node. |
protected SetopNamespace |
createSetopNamespace(SqlCall call,
SqlNode enclosingNode)
Creates a namespace for a set operation (
UNION,
INTERSECT, or EXCEPT). |
protected SqlSelect |
createSourceSelectForDelete(SqlDelete call)
Creates the SELECT statement that putatively feeds rows into a DELETE
statement to be deleted.
|
protected SqlSelect |
createSourceSelectForUpdate(SqlUpdate call)
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)
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.
|
RelDataType |
deriveConstructorType(SqlValidatorScope scope,
SqlCall call,
SqlFunction unresolvedConstructor,
@Nullable SqlFunction resolvedConstructor,
List<RelDataType> argTypes)
Derives the type of a constructor.
|
RelDataType |
deriveType(SqlValidatorScope scope,
SqlNode expr)
Derives the type of a node in a given scope.
|
SqlNode |
expand(SqlNode expr,
SqlValidatorScope scope)
Expands an expression.
|
SqlNode |
expandGroupByOrHavingExpr(SqlNode expr,
SqlValidatorScope scope,
SqlSelect select,
boolean havingExpression) |
SqlNode |
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.
|
SqlNode |
expandSelectExpr(SqlNode expr,
SelectScope scope,
SqlSelect select) |
SqlNodeList |
expandStar(SqlNodeList selectList,
SqlSelect select,
boolean includeSystemVars)
Returns a list of expressions, with every occurrence of "*" or
"TABLE.*" expanded.
|
protected @Nullable SqlNode |
getAggregate(SqlSelect select)
Returns the parse tree node (GROUP BY, HAVING, or an aggregate function
call) that causes
select to be an aggregate query, or null if it
is not an aggregate query. |
SqlValidatorCatalogReader |
getCatalogReader()
Returns the catalog reader used by this validator.
|
SqlConformance |
getConformance() |
SqlValidatorScope |
getCursorScope(SqlSelect select) |
SqlValidatorScope |
getEmptyScope() |
List<List<String>> |
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.
|
@Nullable SqlValidatorScope |
getFromScope(SqlSelect select)
Returns a scope containing the objects visible from the FROM clause of a
query.
|
SqlValidatorScope |
getGroupScope(SqlSelect select)
Returns a scope containing the objects visible from the GROUP BY clause
of a query.
|
SqlValidatorScope |
getHavingScope(SqlSelect select)
Returns a scope containing the objects visible from the HAVING clause of
a query.
|
@Nullable SqlValidatorScope |
getJoinScope(SqlNode node)
Returns a scope containing the objects visible from the ON and USING
sections of a JOIN clause.
|
protected RelDataType |
getLogicalSourceRowType(RelDataType sourceRowType,
SqlInsert insert) |
protected RelDataType |
getLogicalTargetRowType(RelDataType targetRowType,
SqlInsert insert) |
SqlValidatorScope |
getMatchRecognizeScope(SqlMatchRecognize node)
Returns a scope match recognize clause.
|
@Nullable SqlValidatorNamespace |
getNamespace(SqlNode node)
Finds the namespace corresponding to a given node.
|
SqlOperatorTable |
getOperatorTable()
Returns the operator table used by this validator.
|
SqlValidatorScope |
getOrderScope(SqlSelect select)
Returns the scope that expressions in the SELECT and HAVING clause of
this query should use.
|
SqlNode |
getOriginal(SqlNode expr) |
SqlValidatorScope |
getOverScope(SqlNode node)
Returns the scope of an OVER or VALUES node.
|
RelDataType |
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.
|
SqlValidatorScope |
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.
|
TypeCoercion |
getTypeCoercion()
Get the type coercion instance.
|
RelDataTypeFactory |
getTypeFactory()
Returns the type factory used by this validator.
|
RelDataType |
getUnknownType()
Returns an object representing the "unknown" type.
|
RelDataType |
getValidatedNodeType(SqlNode node)
Returns the type assigned to a node by validation.
|
@Nullable RelDataType |
getValidatedNodeTypeIfKnown(SqlNode node)
Returns the type assigned to a node by validation, or null if unknown.
|
@Nullable List<RelDataType> |
getValidatedOperandTypes(SqlCall call)
Returns the types of a call's operands.
|
org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationErrorFunction |
getValidationErrorFunction() |
SqlValidatorScope |
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) |
@Nullable SqlValidatorScope |
getWithScope(SqlNode withItem) |
CalciteException |
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 |
isNestedAggregateWindow(SqlNode node) |
protected boolean |
isOverAggregateWindow(SqlNode node) |
boolean |
isSystemField(RelDataTypeField field)
Returns whether a field is a system field.
|
List<SqlMoniker> |
lookupHints(SqlNode topNode,
SqlParserPos pos)
Looks up completion hints for a syntactically correct SQL statement that
has been parsed into an expression tree.
|
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 a
SqlIdentifier at a given
Parser Position in a parsed expression tree Note: call this only after
SqlValidator.validate(org.apache.calcite.sql.SqlNode) has been called. |
@Nullable SqlCall |
makeNullaryCall(SqlIdentifier id)
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.
|
CalciteContextException |
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 |
popFunctionCall()
Removes the topmost entry from the function call stack.
|
void |
pushFunctionCall()
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.
|
void |
removeValidatedNodeType(SqlNode node)
Removes a node from the set of validated nodes.
|
SqlWindow |
resolveWindow(SqlNode windowOrRef,
SqlValidatorScope scope)
Converts a window specification or window name into a fully-resolved
window specification.
|
void |
setOriginal(SqlNode expr,
SqlNode original) |
void |
setValidatedNodeType(SqlNode node,
RelDataType type)
Saves the type of a
SqlNode, now that it has been validated. |
protected boolean |
shouldAllowIntermediateOrderBy() |
protected boolean |
shouldAllowOverRelation() |
SqlValidator |
transform(UnaryOperator<SqlValidator.Config> transform)
Returns this SqlValidator, with the same state, applying
a transform to the config.
|
@Nullable List<String> |
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.
|
SqlNode |
validate(SqlNode topNode)
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 |
validateColumnListParams(SqlFunction function,
List<RelDataType> argTypes,
List<SqlNode> operands)
Validates a COLUMN_LIST parameter.
|
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 a
SqlIntervalQualifier. |
protected void |
validateJoin(SqlJoin join,
SqlValidatorScope scope) |
void |
validateLiteral(SqlLiteral literal)
Validates a literal.
|
void |
validateMatchRecognize(SqlCall call)
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) |
SqlNode |
validateParameterizedExpression(SqlNode topNode,
Map<String,RelDataType> nameToTypeMap)
Validates an expression tree.
|
void |
validatePivot(SqlPivot pivot) |
void |
validateQuery(SqlNode node,
@Nullable 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) |
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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitresolveWindowpublic static final org.slf4j.Logger TRACER
public static final String UPDATE_SRC_ALIAS
public static final String UPDATE_TGT_ALIAS
public static final String UPDATE_ANON_PREFIX
protected final Map<String,SqlValidatorImpl.IdInfo> idPositions
SqlParserPos strings to the SqlIdentifier identifier
objects at these positions.protected final IdentityHashMap<SqlNode,SqlValidatorScope> scopes
query node objects to the SqlValidatorScope
scope created from them.protected final IdentityHashMap<SqlNode,SqlValidatorNamespace> namespaces
protected final Deque<SqlValidatorImpl.FunctionParamInfo> functionCallStack
protected final RelDataTypeFactory typeFactory
protected final RelDataType unknownType
public final IdentityHashMap<SqlCall,List<RelDataType>> callToOperandTypesMap
getValidatedOperandTypes(SqlCall).protected SqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlValidator.Config config)
opTab - Operator tablecatalogReader - Catalog readertypeFactory - Type factoryconfig - Configpublic SqlConformance getConformance()
@Pure public SqlValidatorCatalogReader getCatalogReader()
SqlValidatorgetCatalogReader in interface SqlValidator@Pure public SqlOperatorTable getOperatorTable()
SqlValidatorgetOperatorTable in interface SqlValidator@Pure public RelDataTypeFactory getTypeFactory()
SqlValidatorgetTypeFactory in interface SqlValidatorpublic RelDataType getUnknownType()
SqlValidatorgetUnknownType in interface SqlValidatorpublic SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
SqlValidatorexpandStar in interface SqlValidatorselectList - Select clause to be expandedselect - QueryincludeSystemVars - Whether to include system variablespublic void declareCursor(SqlSelect select, SqlValidatorScope parentScope)
SqlValidatordeclareCursor in interface SqlValidatorselect - select expression associated with the cursorparentScope - scope of the parent query associated with the cursorpublic void pushFunctionCall()
SqlValidatorpushFunctionCall in interface SqlValidatorpublic void popFunctionCall()
SqlValidatorpopFunctionCall in interface SqlValidatorpublic @Nullable String getParentCursor(String columnListParamName)
SqlValidatorgetParentCursor in interface SqlValidatorcolumnListParamName - name of the column list parameterpublic @Nullable List<String> usingNames(SqlJoin join)
public SqlNode validate(SqlNode topNode)
SqlValidatorvalidate in interface SqlValidatortopNode - top of expression tree to be validatedpublic List<SqlMoniker> lookupHints(SqlNode topNode, SqlParserPos pos)
SqlValidatorWithHintsSqlValidator.validate(org.apache.calcite.sql.SqlNode).lookupHints in interface SqlValidatorWithHintstopNode - 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' schemaSqlMoniker (sql identifiers) that can fill in
at the indicated positionpublic @Nullable SqlMoniker lookupQualifiedName(SqlNode topNode, SqlParserPos pos)
SqlValidatorWithHintsSqlIdentifier at a given
Parser Position in a parsed expression tree Note: call this only after
SqlValidator.validate(org.apache.calcite.sql.SqlNode) has been called.lookupQualifiedName in interface SqlValidatorWithHintstopNode - top of expression tree in which to lookup the qualified
name for the SqlIdentifierpos - indicates the position of the SqlIdentifier in
the SQL statement we want to get the qualified
name forSqlIdentifier
if the Parser position represents a valid SqlIdentifier. Else
return nullpublic final void lookupNameCompletionHints(SqlValidatorScope scope, List<String> names, SqlParserPos pos, Collection<SqlMoniker> hintList)
scope - Validation scopenames - Components of the identifierpos - positionhintList - a list of valid optionspublic SqlNode validateParameterizedExpression(SqlNode topNode, Map<String,RelDataType> nameToTypeMap)
SqlValidatorvalidateParameterizedExpression in interface SqlValidatortopNode - top of expression tree to be validatednameToTypeMap - map of simple name to RelDataType; used to
resolve SqlIdentifier referencespublic void validateQuery(SqlNode node, @Nullable SqlValidatorScope scope, RelDataType targetRowType)
SqlValidatorValid queries include:
SELECT statement,
UNION, INTERSECT,
EXCEPT)
AS operator
validateQuery in interface SqlValidatornode - Query nodescope - Scope in which the query occurstargetRowType - Desired row type, must not be null, may be the data
type 'unknown'.protected void validateNamespace(SqlValidatorNamespace namespace, RelDataType targetRowType)
namespace - NamespacetargetRowType - Desired row type, must not be null, may be the data
type 'unknown'.public SqlValidatorScope getEmptyScope()
public SqlValidatorScope getCursorScope(SqlSelect select)
public SqlValidatorScope getWhereScope(SqlSelect select)
SqlValidatorgetWhereScope in interface SqlValidatorselect - Querypublic SqlValidatorScope getSelectScope(SqlSelect select)
SqlValidatorConsider
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?
SqlValidator.getFromScope(org.apache.calcite.sql.SqlSelect) , you can only see 'foo'.
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'.
SqlValidator.getOrderScope(org.apache.calcite.sql.SqlSelect)), you can see the column alias 'x';
and tables 'emp', 'dept', and 'foo'.
getSelectScope in interface SqlValidatorselect - SELECT statementpublic @Nullable SelectScope getRawSelectScope(SqlSelect select)
SqlValidatorSelectScope; if this is an aggregation query, the
AggregatingScope is stripped away.getRawSelectScope in interface SqlValidatorselect - SELECT statementpublic SqlValidatorScope getHavingScope(SqlSelect select)
SqlValidatorgetHavingScope in interface SqlValidatorselect - SELECT statementpublic SqlValidatorScope getGroupScope(SqlSelect select)
SqlValidatorgetGroupScope in interface SqlValidatorselect - SELECT statementpublic @Nullable SqlValidatorScope getFromScope(SqlSelect select)
SqlValidatorgetFromScope in interface SqlValidatorselect - SELECT statementpublic SqlValidatorScope getOrderScope(SqlSelect select)
SqlValidatorgetOrderScope in interface SqlValidatorselect - SELECT statementpublic SqlValidatorScope getMatchRecognizeScope(SqlMatchRecognize node)
SqlValidatorgetMatchRecognizeScope in interface SqlValidatornode - Match recognizepublic @Nullable SqlValidatorScope getJoinScope(SqlNode node)
SqlValidatorgetJoinScope in interface SqlValidatornode - The item in the FROM clause which contains the ON or USING
expressionSqlValidator.getFromScope(org.apache.calcite.sql.SqlSelect)public SqlValidatorScope getOverScope(SqlNode node)
SqlValidatorgetOverScope in interface SqlValidatornode - Nodepublic @Nullable SqlValidatorNamespace getNamespace(SqlNode node)
SqlValidatorFor example, in the query SELECT * FROM (SELECT * FROM t), t1 AS
alias, the both items in the FROM clause have a corresponding
namespace.
getNamespace in interface SqlValidatornode - Parse tree nodeprotected @PolyNull SqlNode performUnconditionalRewrites(@PolyNull SqlNode node, boolean underFrom)
Returns null if and only if the original expression is null.
node - expression to be rewrittenunderFrom - whether node appears directly under a FROM clauseprotected @Nullable SqlNode getSelfJoinExprForUpdate(SqlNode table, String alias)
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.protected SqlSelect createSourceSelectForUpdate(SqlUpdate call)
call - Call to the UPDATE operatorprotected SqlSelect createSourceSelectForDelete(SqlDelete call)
call - Call to the DELETE operatorpublic RelDataType getValidatedNodeType(SqlNode node)
SqlValidatorgetValidatedNodeType in interface SqlValidatornode - the node of interestpublic @Nullable RelDataType getValidatedNodeTypeIfKnown(SqlNode node)
SqlValidatorSqlValidator.getValidatedNodeType(org.apache.calcite.sql.SqlNode) instead.getValidatedNodeTypeIfKnown in interface SqlValidatornode - the node of interestpublic @Nullable List<RelDataType> getValidatedOperandTypes(SqlCall call)
SqlValidatorReturns 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.
getValidatedOperandTypes in interface SqlValidatorcall - Callpublic final void setValidatedNodeType(SqlNode node, RelDataType type)
SqlNode, 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.
setValidatedNodeType in interface SqlValidatornode - A SQL parse tree node, never nulltype - Its type; must not be nullpublic void removeValidatedNodeType(SqlNode node)
SqlValidatorremoveValidatedNodeType in interface SqlValidatornode - node to be removedpublic @Nullable SqlCall makeNullaryCall(SqlIdentifier id)
SqlValidatormakeNullaryCall in interface SqlValidatorpublic RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
SqlValidatorderiveType in interface SqlValidatorscope - Syntactic scopeexpr - Parse tree nodeNULLpublic RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes)
SqlValidatorderiveConstructorType in interface SqlValidatorscope - Scopecall - CallunresolvedConstructor - TODOresolvedConstructor - TODOargTypes - Types of argumentspublic CalciteException handleUnresolvedFunction(SqlCall call, SqlOperator unresolvedFunction, List<RelDataType> argTypes, @Nullable List<String> argNames)
SqlValidatorhandleUnresolvedFunction in interface SqlValidatorcall - CallunresolvedFunction - Overloaded function which is the target of the
callargTypes - Types of argumentsargNames - Names of arguments, or null if call by positionprotected void inferUnknownTypes(RelDataType inferredType, SqlValidatorScope scope, SqlNode node)
protected void addToSelectList(List<SqlNode> list, Set<String> aliases, List<Map.Entry<String,RelDataType>> fieldList, SqlNode exp, SelectScope scope, boolean includeSystemVars)
public @Nullable String deriveAlias(SqlNode node, int ordinal)
SqlValidatorordinal is less than zero, otherwise generates an
alias EXPR$ordinal.deriveAlias in interface SqlValidatornode - Expressionordinal - Ordinal of expressionprotected boolean shouldAllowIntermediateOrderBy()
protected MatchRecognizeNamespace createMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode)
protected PivotNamespace createPivotNameSpace(SqlPivot call, SqlNode enclosingNode)
protected UnpivotNamespace createUnpivotNameSpace(SqlUnpivot call, SqlNode enclosingNode)
protected void registerNamespace(@Nullable SqlValidatorScope usingScope, @Nullable String alias, SqlValidatorNamespace ns, boolean forceNullable)
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 nullableprotected boolean shouldAllowOverRelation()
protected SelectNamespace createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
SELECT node. Derived class may
override this factory method.select - Select nodeenclosingNode - Enclosing nodeprotected SetopNamespace createSetopNamespace(SqlCall call, SqlNode enclosingNode)
UNION,
INTERSECT, or EXCEPT). Derived class may override
this factory method.call - Call to set operationenclosingNode - Enclosing nodepublic boolean isAggregate(SqlSelect select)
SqlValidatorSUM(x) OVER w, don't count.)isAggregate in interface SqlValidatorselect - SELECT statementprotected boolean isNestedAggregateWindow(SqlNode node)
protected boolean isOverAggregateWindow(SqlNode node)
protected @Nullable SqlNode getAggregate(SqlSelect select)
select 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.
@Deprecated public boolean isAggregate(SqlNode selectNode)
SqlValidatorisAggregate in interface SqlValidatorselectNode - Expression in SELECT clausepublic void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
SqlValidatorvalidateIdentifier in interface SqlValidatorid - Identifierscope - Naming scopepublic void validateLiteral(SqlLiteral literal)
SqlValidatorvalidateLiteral in interface SqlValidatorliteral - Literalpublic void validateIntervalQualifier(SqlIntervalQualifier qualifier)
SqlValidatorSqlIntervalQualifier.validateIntervalQualifier in interface SqlValidatorqualifier - Interval qualifierprotected void validateFrom(SqlNode node, RelDataType targetRowType, SqlValidatorScope scope)
node - Node in FROM clause, typically a table or derived
tabletargetRowType - Desired row type of this expression, or
unknownType if not fussy. Must not be null.scope - Scopeprotected void validateTableFunction(SqlCall node, SqlValidatorScope scope, RelDataType targetRowType)
protected void validateOver(SqlCall call, SqlValidatorScope scope)
protected void validateUnnest(SqlCall call, SqlValidatorScope scope, RelDataType targetRowType)
protected void validateJoin(SqlJoin join, SqlValidatorScope scope)
protected void validateSelect(SqlSelect select, RelDataType targetRowType)
select - Select statementtargetRowType - Desired row type, must not be null, may be the data
type 'unknown'.public boolean validateModality(SqlSelect select, SqlModality modality, boolean fail)
SqlValidatorvalidateModality in interface SqlValidatorselect - Querymodality - Modality (streaming or relational)fail - Whether to throw a user error if does not support required
modalityprotected void validateWindowClause(SqlSelect select)
public void validateWith(SqlWith with, SqlValidatorScope scope)
validateWith in interface SqlValidatorpublic void validateWithItem(SqlWithItem withItem)
validateWithItem in interface SqlValidatorpublic void validateSequenceValue(SqlValidatorScope scope, SqlIdentifier id)
validateSequenceValue in interface SqlValidatorpublic @Nullable SqlValidatorScope getWithScope(SqlNode withItem)
getWithScope in interface SqlValidatorpublic TypeCoercion getTypeCoercion()
SqlValidatorgetTypeCoercion in interface SqlValidatorpublic SqlValidator.Config config()
SqlValidatorconfig in interface SqlValidatorpublic SqlValidator transform(UnaryOperator<SqlValidator.Config> transform)
SqlValidatorThis is mainly used for tests, otherwise constructs a SqlValidator.Config directly
through the constructor.
transform in interface SqlValidatorprotected void validateOrderList(SqlSelect select)
select - Select statementpublic SqlNode expandOrderExpr(SqlSelect select, SqlNode orderExpr)
SqlValidatorThis is made necessary by a couple of dialect 'features':
expandOrderExpr in interface SqlValidatorselect - Select statement which contains ORDER BYorderExpr - Expression in the ORDER BY clause.protected void validateGroupClause(SqlSelect select)
protected void validateWhereClause(SqlSelect select)
protected void validateWhereOrOn(SqlValidatorScope scope, SqlNode condition, String clause)
protected void validateHavingClause(SqlSelect select)
protected RelDataType validateSelectList(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType)
protected RelDataType createTargetRowType(SqlValidatorTable table, @Nullable SqlNodeList targetColumnList, boolean append)
table - Target table for INSERT/UPDATEtargetColumnList - List of target columns, or null if not specifiedappend - Whether to append fields to those in
baseRowTypepublic void validateInsert(SqlInsert insert)
SqlValidatorvalidateInsert in interface SqlValidatorinsert - INSERT statementprotected RelDataType getLogicalTargetRowType(RelDataType targetRowType, SqlInsert insert)
protected RelDataType getLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert)
protected void checkTypeAssignment(@Nullable SqlValidatorScope sourceScope, SqlValidatorTable table, RelDataType sourceRowType, RelDataType targetRowType, SqlNode 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.
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 querypublic void validateDelete(SqlDelete call)
SqlValidatorvalidateDelete in interface SqlValidatorcall - DELETE statementpublic void validateUpdate(SqlUpdate call)
SqlValidatorvalidateUpdate in interface SqlValidatorcall - UPDATE statementpublic void validateMerge(SqlMerge call)
SqlValidatorvalidateMerge in interface SqlValidatorcall - MERGE statementprotected void validateValues(SqlCall node, RelDataType targetRowType, SqlValidatorScope scope)
node - Values clausetargetRowType - Row type which expression must conform toscope - Scope within which clause occurspublic void validateDataType(SqlDataTypeSpec dataType)
SqlValidatorvalidateDataType in interface SqlValidatordataType - Data typepublic void validateDynamicParam(SqlDynamicParam dynamicParam)
SqlValidatorvalidateDynamicParam in interface SqlValidatordynamicParam - Dynamic parameterpublic org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationErrorFunction getValidationErrorFunction()
public CalciteContextException newValidationError(SqlNode node, org.apache.calcite.runtime.Resources.ExInst<SqlValidatorException> e)
SqlValidatorNote that the input exception is checked (it derives from
Exception) and the output exception is unchecked (it derives from
RuntimeException). This is intentional -- it should remind code
authors to provide context for their validation errors.
newValidationError in interface SqlValidatornode - The place where the exception occurred, not nulle - The validation errorprotected SqlWindow getWindowByName(SqlIdentifier id, SqlValidatorScope scope)
public SqlWindow resolveWindow(SqlNode windowOrRef, SqlValidatorScope scope)
SqlValidatorSELECT 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).resolveWindow in interface SqlValidatorwindowOrRef - Either the name of a window (a SqlIdentifier)
or a window specification (a SqlWindow).scope - Scope in which to resolve window namespublic void validateWindow(SqlNode windowOrId, SqlValidatorScope scope, @Nullable SqlCall call)
SqlValidatoridentifier referencing a window, or an
inline window specification.validateWindow in interface SqlValidatorwindowOrId - 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.public void validateMatchRecognize(SqlCall call)
SqlValidatorvalidateMatchRecognize in interface SqlValidatorcall - MATCH_RECOGNIZE clausepublic void validatePivot(SqlPivot pivot)
public void validateUnpivot(SqlUnpivot unpivot)
public void validateAggregateParams(SqlCall aggCall, @Nullable SqlNode filter, @Nullable SqlNodeList distinctList, @Nullable SqlNodeList orderList, SqlValidatorScope scope)
SqlValidatorvalidateAggregateParams in interface SqlValidatoraggCall - 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 scopepublic void validateCall(SqlCall call, SqlValidatorScope scope)
SqlValidatorvalidateCall in interface SqlValidatorcall - Operator callscope - Naming scopeprotected void validateFeature(Feature feature, SqlParserPos context)
feature - feature being used, represented as a resource instancecontext - parser position context for error reporting, or null ifpublic SqlNode expandSelectExpr(SqlNode expr, SelectScope scope, SqlSelect select)
public SqlNode expand(SqlNode expr, SqlValidatorScope scope)
SqlValidatorexpand in interface SqlValidatorexpr - Expressionscope - Scopepublic SqlNode expandGroupByOrHavingExpr(SqlNode expr, SqlValidatorScope scope, SqlSelect select, boolean havingExpression)
public boolean isSystemField(RelDataTypeField field)
SqlValidatorIn the default implementation, always returns false.
isSystemField in interface SqlValidatorfield - Fieldpublic List<List<String>> getFieldOrigins(SqlNode sqlQuery)
SqlValidatorThe 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.
getFieldOrigins in interface SqlValidatorsqlQuery - Querypublic RelDataType getParameterRowType(SqlNode sqlQuery)
SqlValidatorgetParameterRowType in interface SqlValidatorsqlQuery - Querypublic void validateColumnListParams(SqlFunction function, List<RelDataType> argTypes, List<SqlNode> operands)
SqlValidatorvalidateColumnListParams in interface SqlValidatorfunction - function containing COLUMN_LIST parameterargTypes - function argumentsoperands - operands passed into the function callCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.