Package org.apache.calcite.sql.advise
Class SqlAdvisorValidator
- java.lang.Object
-
- org.apache.calcite.sql.validate.SqlValidatorImpl
-
- org.apache.calcite.sql.advise.SqlAdvisorValidator
-
- All Implemented Interfaces:
SqlValidator
,SqlValidatorWithHints
public class SqlAdvisorValidator extends SqlValidatorImpl
SqlAdvisorValidator
is used bySqlAdvisor
to traverse the parse tree of a SQL statement, not for validation purpose but for setting up the scopes and namespaces to facilitate retrieval of SQL statement completion hints.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.calcite.sql.validate.SqlValidatorImpl
SqlValidatorImpl.DmlNamespace, SqlValidatorImpl.FunctionParamInfo, SqlValidatorImpl.IdInfo, SqlValidatorImpl.Status
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<SqlValidatorNamespace>
activeNamespaces
private RelDataType
emptyStructType
-
Fields inherited from class org.apache.calcite.sql.validate.SqlValidatorImpl
expandColumnReferences, expandIdentifiers, functionCallStack, idPositions, namespaces, scopes, TRACER, typeFactory, unknownType, UPDATE_ANON_PREFIX, UPDATE_SRC_ALIAS, UPDATE_TGT_ALIAS
-
Fields inherited from interface org.apache.calcite.sql.validate.SqlValidator
STRICT
-
-
Constructor Summary
Constructors Constructor Description SqlAdvisorValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance)
Creates a SqlAdvisor validator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RelDataType
deriveType(SqlValidatorScope scope, SqlNode operand)
Calls the parent class method and mask Farrago exception thrown.SqlNode
expand(SqlNode expr, SqlValidatorScope scope)
Expands an expression.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.private void
registerId(SqlIdentifier id, SqlValidatorScope scope)
protected boolean
shouldAllowOverRelation()
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
validateHavingClause(SqlSelect select)
Calls the parent class method and masks Farrago exception thrown.void
validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
Registers the identifier and its scope into a map keyed by ParserPosition.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
validateOver(SqlCall call, SqlValidatorScope scope)
protected void
validateWhereClause(SqlSelect select)
Calls the parent class method and masks Farrago exception thrown.-
Methods inherited from class org.apache.calcite.sql.validate.SqlValidatorImpl
addToSelectList, checkTypeAssignment, createMatchRecognizeNameSpace, createSelectNamespace, createSetopNamespace, createSourceSelectForDelete, createSourceSelectForUpdate, createTargetRowType, declareCursor, deriveAlias, deriveConstructorType, expandGroupByOrHavingExpr, expandStar, getAggregate, getCatalogReader, getColumnReferenceExpansion, getConformance, getCursorScope, getDefaultNullCollation, getEmptyScope, getFieldOrigins, getFromScope, getGroupScope, getHavingScope, getJoinScope, getLogicalSourceRowType, getLogicalTargetRowType, getMatchRecognizeScope, getNamespace, getOperatorTable, getOrderScope, getOriginal, getOverScope, getParameterRowType, getParentCursor, getRawSelectScope, getSelectScope, getSelfJoinExprForUpdate, getTypeFactory, getUnknownType, getValidatedNodeType, getValidatedNodeTypeIfKnown, getValidationErrorFunction, getWhereScope, getWindowByName, getWithScope, handleUnresolvedFunction, inferUnknownTypes, isAggregate, isAggregate, isNestedAggregateWindow, isOverAggregateWindow, isSystemField, lookupHints, lookupNameCompletionHints, lookupQualifiedName, newValidationError, performUnconditionalRewrites, popFunctionCall, pushFunctionCall, registerNamespace, removeValidatedNodeType, resolveWindow, setCallRewrite, setColumnReferenceExpansion, setDefaultNullCollation, setIdentifierExpansion, setOriginal, setValidatedNodeType, shouldAllowIntermediateOrderBy, shouldExpandIdentifiers, validate, validateAggregateParams, validateCall, validateColumnListParams, validateDataType, validateDelete, validateDynamicParam, validateFeature, validateGroupClause, validateInsert, validateIntervalQualifier, validateJoin, validateLiteral, validateMatchRecognize, validateMerge, validateOrderList, validateParameterizedExpression, validateQuery, validateSelect, validateSelectList, validateSequenceValue, validateUnnest, validateUpdate, validateValues, validateWhereOrOn, validateWindow, validateWindowClause, validateWith, validateWithItem
-
-
-
-
Field Detail
-
activeNamespaces
private final java.util.Set<SqlValidatorNamespace> activeNamespaces
-
emptyStructType
private final RelDataType emptyStructType
-
-
Constructor Detail
-
SqlAdvisorValidator
public SqlAdvisorValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance)
Creates a SqlAdvisor validator.- Parameters:
opTab
- Operator tablecatalogReader
- Catalog readertypeFactory
- Type factoryconformance
- Compatibility mode
-
-
Method Detail
-
validateIdentifier
public void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
Registers the identifier and its scope into a map keyed by ParserPosition.- Specified by:
validateIdentifier
in interfaceSqlValidator
- Overrides:
validateIdentifier
in classSqlValidatorImpl
- Parameters:
id
- Identifierscope
- Naming scope
-
registerId
private void registerId(SqlIdentifier id, SqlValidatorScope scope)
-
expand
public SqlNode expand(SqlNode expr, SqlValidatorScope scope)
Description copied from interface:SqlValidator
Expands an expression.- Specified by:
expand
in interfaceSqlValidator
- Overrides:
expand
in classSqlValidatorImpl
- Parameters:
expr
- Expressionscope
- Scope- Returns:
- Expanded expression
-
expandOrderExpr
public SqlNode expandOrderExpr(SqlSelect select, SqlNode orderExpr)
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
- Overrides:
expandOrderExpr
in classSqlValidatorImpl
- Parameters:
select
- Select statement which contains ORDER BYorderExpr
- Expression in the ORDER BY clause.- Returns:
- Expression translated into SELECT clause semantics
-
deriveType
public RelDataType deriveType(SqlValidatorScope scope, SqlNode operand)
Calls the parent class method and mask Farrago exception thrown.- Specified by:
deriveType
in interfaceSqlValidator
- Overrides:
deriveType
in classSqlValidatorImpl
- Parameters:
scope
- Syntactic scopeoperand
- Parse tree node- Returns:
- Type of the SqlNode. Should never return
NULL
-
validateFrom
protected void validateFrom(SqlNode node, RelDataType targetRowType, SqlValidatorScope scope)
Description copied from class:SqlValidatorImpl
Validates the FROM clause of a query, or (recursively) a child node of the FROM clause: AS, OVER, JOIN, VALUES, or sub-query.- Overrides:
validateFrom
in classSqlValidatorImpl
- Parameters:
node
- Node in FROM clause, typically a table or derived tabletargetRowType
- Desired row type of this expression, orSqlValidatorImpl.unknownType
if not fussy. Must not be null.scope
- Scope
-
validateWhereClause
protected void validateWhereClause(SqlSelect select)
Calls the parent class method and masks Farrago exception thrown.- Overrides:
validateWhereClause
in classSqlValidatorImpl
-
validateHavingClause
protected void validateHavingClause(SqlSelect select)
Calls the parent class method and masks Farrago exception thrown.- Overrides:
validateHavingClause
in classSqlValidatorImpl
-
validateOver
protected void validateOver(SqlCall call, SqlValidatorScope scope)
- Overrides:
validateOver
in classSqlValidatorImpl
-
validateNamespace
protected void validateNamespace(SqlValidatorNamespace namespace, RelDataType targetRowType)
Description copied from class:SqlValidatorImpl
Validates a namespace.- Overrides:
validateNamespace
in classSqlValidatorImpl
- Parameters:
namespace
- NamespacetargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
validateModality
public boolean validateModality(SqlSelect select, SqlModality modality, boolean fail)
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
- Overrides:
validateModality
in classSqlValidatorImpl
- 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
-
shouldAllowOverRelation
protected boolean shouldAllowOverRelation()
- Overrides:
shouldAllowOverRelation
in classSqlValidatorImpl
-
-