Class SqlValidatorImpl
- java.lang.Object
-
- org.apache.calcite.sql.validate.SqlValidatorImpl
-
- All Implemented Interfaces:
SqlValidator
,SqlValidatorWithHints
- Direct Known Subclasses:
CalciteSqlValidator
,SqlAdvisorValidator
public class SqlValidatorImpl extends java.lang.Object implements SqlValidatorWithHints
Default implementation ofSqlValidator
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SqlValidatorImpl.DeleteNamespace
Namespace for a DELETE statement.private class
SqlValidatorImpl.DeriveTypeVisitor
Visitor which derives the type of a givenSqlNode
.static class
SqlValidatorImpl.DmlNamespace
Common base class for DML statement namespaces.private static class
SqlValidatorImpl.Expander
Converts an expression into canonical form by fully-qualifying any identifiers.(package private) static class
SqlValidatorImpl.ExtendedExpander
Shuttle which walks over an expression in the GROUP BY/HAVING clause, replacing usages of aliases or ordinals with the underlying expression.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.private static class
SqlValidatorImpl.InsertNamespace
Namespace for an INSERT statement.private static class
SqlValidatorImpl.MergeNamespace
Namespace for a MERGE statement.private static class
SqlValidatorImpl.NavigationExpander
Shuttle that expands navigation expressions in a MATCH_RECOGNIZE clause.private static class
SqlValidatorImpl.NavigationModifier
Modify the nodes in navigation function such as FIRST, LAST, PREV AND NEXT.private static class
SqlValidatorImpl.NavigationReplacer
Shuttle that replacesA as A.price > PREV(B.price)
withPREV(A.price, 0) > LAST(B.price, 0)
.(package private) class
SqlValidatorImpl.OrderExpressionExpander
Shuttle which walks over an expression in the ORDER BY clause, replacing usages of aliases with the underlying expression.private class
SqlValidatorImpl.PatternValidator
Within one navigation function, the pattern var should be sameprivate class
SqlValidatorImpl.PatternVarVisitor
retrieve pattern variables definedprivate class
SqlValidatorImpl.Permute
Permutation of fields in NATURAL JOIN or USING.static class
SqlValidatorImpl.Status
Validation status.private static class
SqlValidatorImpl.UpdateNamespace
Namespace for an UPDATE statement.private class
SqlValidatorImpl.ValidationError
Throws a validator exception with access to the validator context.(package private) class
SqlValidatorImpl.ValidationErrorFunction
Throws a validator exception with access to the validator context.
-
Field Summary
Fields Modifier and Type Field Description private AggFinder
aggFinder
private AggFinder
aggOrOverFinder
private AggFinder
aggOrOverOrGroupFinder
private RelDataType
booleanType
(package private) SqlValidatorCatalogReader
catalogReader
private SqlConformance
conformance
private java.util.Map<SqlSelect,SqlValidatorScope>
cursorScopes
Maps aSqlSelect
node that is the argument to a CURSOR constructor to the scope of the result of that select nodeprivate java.util.Set<SqlNode>
cursorSet
Set of select expressions used as cursor definitions.protected boolean
expandColumnReferences
protected boolean
expandIdentifiers
protected java.util.Deque<SqlValidatorImpl.FunctionParamInfo>
functionCallStack
Stack of objects that maintain information about function calls.private java.util.Map<SqlSelect,SqlValidatorScope>
groupByScopes
Maps aSqlSelect
node to the scope used by its GROUP BY clause.private AggFinder
groupFinder
protected java.util.Map<java.lang.String,SqlValidatorImpl.IdInfo>
idPositions
Maps ParsePosition strings to theSqlIdentifier
identifier objects at these positionsprivate boolean
inWindow
protected java.util.Map<SqlNode,SqlValidatorNamespace>
namespaces
private int
nextGeneratedId
private java.util.Map<SqlNode,RelDataType>
nodeToTypeMap
Map of derived RelDataType for each node.private NullCollation
nullCollation
private SqlOperatorTable
opTab
private java.util.Map<SqlSelect,SqlValidatorScope>
orderScopes
Maps aSqlSelect
node to the scope used by its ORDER BY clause.private java.util.Map<SqlNode,SqlNode>
originalExprs
private AggFinder
overFinder
private boolean
rewriteCalls
protected java.util.Map<SqlNode,SqlValidatorScope>
scopes
Mapsquery node
objects to theSqlValidatorScope
scope created from them.private java.util.Map<SqlSelect,SqlValidatorScope>
selectScopes
Maps aSqlSelect
node to the scope used by its SELECT and HAVING clauses.private TableScope
tableScope
The name-resolution scope of a LATERAL TABLE clause.private SqlNode
top
static org.slf4j.Logger
TRACER
protected RelDataTypeFactory
typeFactory
protected RelDataType
unknownType
The type of dynamic parameters until a type is imposed on them.static java.lang.String
UPDATE_ANON_PREFIX
Alias prefix generated for source columns when rewriting UPDATE to MERGE.static java.lang.String
UPDATE_SRC_ALIAS
Alias generated for the source table when rewriting UPDATE to MERGE.static java.lang.String
UPDATE_TGT_ALIAS
Alias generated for the target table when rewriting UPDATE to MERGE if no alias was specified by the user.private boolean
validatingSqlMerge
private SqlValidatorImpl.ValidationErrorFunction
validationErrorFunction
private java.util.Map<SqlSelect,SqlValidatorScope>
whereScopes
Maps aSqlSelect
node to the scope used by its WHERE and HAVING clauses.-
Fields inherited from interface org.apache.calcite.sql.validate.SqlValidator
STRICT
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance)
Creates a validator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
addOrExpandField(java.util.List<SqlNode> selectItems, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fields, boolean includeSystemVars, SelectScope scope, SqlIdentifier id, RelDataTypeField field)
protected void
addToSelectList(java.util.List<SqlNode> list, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fieldList, SqlNode exp, SqlValidatorScope scope, boolean includeSystemVars)
Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list.private static java.lang.String
alias(SqlNode item)
Returns the alias of a "expr AS alias" expression.private void
checkConstraint(SqlValidatorTable validatorTable, SqlNode source, RelDataType targetRowType)
Validates insert values against the constraint of a modifiable view.private void
checkConstraint(SqlValidatorTable validatorTable, SqlUpdate update, RelDataType targetRowType)
Validates updates against the constraint of a modifiable view.private void
checkFieldCount(SqlNode node, SqlValidatorTable table, SqlNode source, RelDataType logicalSourceRowType, RelDataType logicalTargetRowType)
private void
checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope)
private void
checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, java.lang.String optionalClause)
private void
checkRollUpInGroupBy(SqlSelect select)
private void
checkRollUpInOrderBy(SqlSelect select)
private void
checkRollUpInSelectList(SqlSelect select)
private void
checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight)
private void
checkRollUpInWindow(SqlWindow window, SqlValidatorScope scope)
private void
checkRollUpInWindowDecl(SqlSelect select)
protected void
checkTypeAssignment(RelDataType sourceRowType, RelDataType targetRowType, SqlNode query)
protected MatchRecognizeNamespace
createMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode)
protected SelectNamespace
createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
Creates a namespace for aSELECT
node.protected SetopNamespace
createSetopNamespace(SqlCall call, SqlNode enclosingNode)
Creates a namespace for a set operation (UNION
,INTERSECT
, orEXCEPT
).protected SqlSelect
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, SqlNodeList targetColumnList, boolean append)
Derives a row-type for INSERT and UPDATE operations.void
declareCursor(SqlSelect select, SqlValidatorScope parentScope)
Declares a SELECT expression as a cursor.private SqlModality
deduceModality(SqlNode query)
Return the intended modality of a SELECT or set-op.java.lang.String
deriveAlias(SqlNode node, int ordinal)
Derives an alias for an expression.RelDataType
deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, java.util.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.(package private) RelDataType
deriveTypeImpl(SqlValidatorScope scope, SqlNode operand)
Derives the type of a node, never null.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.private boolean
expandSelectItem(SqlNode selectItem, SqlSelect select, RelDataType targetType, java.util.List<SqlNode> selectItems, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fields, boolean includeSystemVars)
IfselectItem
is "*" or "TABLE.*", expands it and returns true; otherwise writes the unexpanded item.private boolean
expandStar(java.util.List<SqlNode> selectItems, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fields, boolean includeSystemVars, SelectScope scope, SqlNode node)
SqlNodeList
expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded.private static void
findAllValidFunctionNames(java.util.List<java.lang.String> names, SqlValidator validator, java.util.Collection<SqlMoniker> result, SqlParserPos pos)
private static void
findAllValidUdfNames(java.util.List<java.lang.String> names, SqlValidator validator, java.util.Collection<SqlMoniker> result)
private Table
findTable(java.lang.String alias)
Given a table alias, find the correspondingTable
associated with itprivate Table
findTable(CalciteSchema schema, java.lang.String tableName, boolean caseSensitive)
private Pair<java.lang.String,java.lang.String>
findTableColumnPair(SqlIdentifier identifier, SqlValidatorScope scope)
private SqlNode
getAgg(SqlSelect select)
If there is at least one call to an aggregate function, returns the first.protected SqlNode
getAggregate(SqlSelect select)
Returns the parse tree node (GROUP BY, HAVING, or an aggregate function call) that causesselect
to be an aggregate query, or null if it is not an aggregate query.SqlValidatorCatalogReader
getCatalogReader()
Returns the catalog reader used by this validator.boolean
getColumnReferenceExpansion()
SqlConformance
getConformance()
Returns the dialect of SQL (SQL:2003, etc.) this validator recognizes.SqlValidatorScope
getCursorScope(SqlSelect select)
NullCollation
getDefaultNullCollation()
Returns how NULL values should be collated if an ORDER BY item does not contain NULLS FIRST or NULLS LAST.SqlValidatorScope
getEmptyScope()
private java.util.List<java.lang.String>
getFieldOrigin(SqlNode sqlQuery, int i)
java.util.List<java.util.List<java.lang.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.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.private SqlSelect
getInnerSelect(SqlNode node)
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.private SqlValidatorNamespace
getNamespace(SqlIdentifier id, DelegatingScope scope)
SqlValidatorNamespace
getNamespace(SqlNode node)
Finds the namespace corresponding to a given node.private SqlValidatorNamespace
getNamespace(SqlNode node, SqlValidatorScope scope)
private SqlNode
getNthExpr(SqlNode query, int ordinal, int sourceCount)
Locates the n'th expression in an INSERT or UPDATE query.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.java.lang.String
getParentCursor(java.lang.String columnListParamName)
Retrieves the name of the parent cursor referenced by a column list parameter.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 SqlNode
getSelfJoinExprForUpdate(SqlNode table, java.lang.String alias)
Allows a subclass to provide information about how to convert an UPDATE into a MERGE via self-join.(package private) RelDataType
getTableConstructorRowType(SqlCall values, SqlValidatorScope scope)
Returns null if there is no common type.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.RelDataType
getValidatedNodeTypeIfKnown(SqlNode node)
Returns the type assigned to a node by validation, or null if unknown.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)
private SqlWindow
getWindowInOver(SqlNode over)
SqlValidatorScope
getWithScope(SqlNode withItem)
private void
handleOffsetFetch(SqlNode offset, SqlNode fetch)
private void
handleScalarSubQuery(SqlSelect parentSelect, SqlSelect selectItem, java.util.List<SqlNode> expandedSelectItems, java.util.Set<java.lang.String> aliasList, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fieldList)
Processes SubQuery found in Select list.CalciteException
handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, java.util.List<RelDataType> argTypes, java.util.List<java.lang.String> argNames)
Handles a call to a function which cannot be resolved.private boolean
hasSortedPrefix(SelectScope scope, SqlNodeList orderList)
Returns whether the prefix is sorted.protected void
inferUnknownTypes(RelDataType inferredType, SqlValidatorScope scope, SqlNode node)
boolean
isAggregate(SqlNode selectNode)
Returns whether a select list expression is an aggregate function.boolean
isAggregate(SqlSelect select)
Returns whether a SELECT statement is an aggregation.private static boolean
isAggregation(SqlKind kind)
private static boolean
isLateral(SqlNode node)
private static boolean
isLogicalNavigation(SqlKind kind)
protected boolean
isNestedAggregateWindow(SqlNode node)
protected boolean
isOverAggregateWindow(SqlNode node)
private static boolean
isPhysicalNavigation(SqlKind kind)
private boolean
isRolledUpColumn(SqlIdentifier identifier, SqlValidatorScope scope)
private boolean
isRolledUpColumnAllowedInAgg(SqlIdentifier identifier, SqlValidatorScope scope, SqlCall aggCall, SqlNode parent)
private boolean
isRowWithDefault(SqlNode operand, int column)
private static boolean
isRunningOrFinal(SqlKind kind)
private static boolean
isSingleVarRequired(SqlKind kind)
private boolean
isSortCompatible(SelectScope scope, SqlNode node, boolean descending)
boolean
isSystemField(RelDataTypeField field)
Returns whether a field is a system field.private boolean
isValuesWithDefault(SqlNode source, int column)
Returns whether a query usesDEFAULT
to populate a given column.(package private) SqlValidatorNamespace
lookupFieldNamespace(RelDataType rowType, java.lang.String name)
private void
lookupFromHints(SqlNode node, SqlValidatorScope scope, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
java.util.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.private void
lookupJoinHints(SqlJoin join, SqlValidatorScope scope, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
void
lookupNameCompletionHints(SqlValidatorScope scope, java.util.List<java.lang.String> names, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
Populates a list of all the valid alternatives for an identifier.SqlMoniker
lookupQualifiedName(SqlNode topNode, SqlParserPos pos)
Looks up the fully qualified name for aSqlIdentifier
at a given Parser Position in a parsed expression tree Note: call this only afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)
has been called.(package private) void
lookupSelectHints(SqlSelect select, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
Looks up completion hints for a syntactically correct select SQL that has been parsed into an expression tree.private void
lookupSelectHints(SqlValidatorNamespace ns, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
private SqlNode
maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType)
private SqlNode
navigationInDefine(SqlNode node, java.lang.String alpha)
Checks that all pattern variables within a function are the same, and canonizes expressions such asPREV(B.price)
toLAST(B.price, 0)
.private SqlNode
navigationInMeasure(SqlNode node, boolean allRows)
CalciteContextException
newValidationError(SqlNode node, Resources.ExInst<SqlValidatorException> e)
Adds "line x, column y" context to a validator exception.protected SqlNode
performUnconditionalRewrites(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.private SqlNode
registerFrom(SqlValidatorScope parentScope, SqlValidatorScope usingScope, boolean register, SqlNode node, SqlNode enclosingNode, java.lang.String alias, SqlNodeList extendList, boolean forceNullable, boolean lateral)
Registers scopes and namespaces implied a relational expression in the FROM clause.private void
registerMatchRecognize(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlMatchRecognize call, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable)
protected void
registerNamespace(SqlValidatorScope usingScope, java.lang.String alias, SqlValidatorNamespace ns, boolean forceNullable)
Registers a new namespace, and adds it as a child of its parent scope.private void
registerOperandSubQueries(SqlValidatorScope parentScope, SqlCall call, int operandOrdinal)
Registers any sub-queries inside a given call operand, and converts the operand to a scalar sub-query if the operator requires it.private void
registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable)
Registers a query in a parent scope.private void
registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable, boolean checkUpdate)
Registers a query in a parent scope.private void
registerSetop(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable)
private void
registerSubQueries(SqlValidatorScope parentScope, SqlNode node)
private void
registerWith(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlWith with, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable, boolean checkUpdate)
void
removeValidatedNodeType(SqlNode node)
Removes a node from the set of validated nodesSqlWindow
resolveWindow(SqlNode windowOrRef, SqlValidatorScope scope, boolean populateBounds)
Converts a window specification or window name into a fully-resolved window specification.private void
rewriteMerge(SqlMerge call)
private SqlNode
rewriteUpdateToMerge(SqlUpdate updateCall, SqlNode selfJoinSrcExpr)
void
setCallRewrite(boolean rewriteCalls)
Enables or disables rewrite of "macro-like" calls such as COALESCE.void
setColumnReferenceExpansion(boolean expandColumnReferences)
Enables or disables expansion of column references.void
setDefaultNullCollation(NullCollation nullCollation)
Sets how NULL values should be collated if an ORDER BY item does not contain NULLS FIRST or NULLS LAST.void
setIdentifierExpansion(boolean expandIdentifiers)
Enables or disables expansion of identifiers other than column references.void
setOriginal(SqlNode expr, SqlNode original)
void
setValidatedNodeType(SqlNode node, RelDataType type)
Saves the type of aSqlNode
, now that it has been validated.protected boolean
shouldAllowIntermediateOrderBy()
protected boolean
shouldAllowOverRelation()
private boolean
shouldCheckForRollUp(SqlNode from)
boolean
shouldExpandIdentifiers()
Returns expansion of identifiers.private SqlNode
stripDot(SqlNode node)
private static SqlNode
stripOver(SqlNode node)
SqlNode
validate(SqlNode topNode)
Validates an expression tree.private void
validateAccess(SqlNode node, SqlValidatorTable table, SqlAccessEnum requiredAccess)
Validates access to a table.void
validateAggregateParams(SqlCall aggCall, SqlNode filter, 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, java.util.List<RelDataType> argTypes, java.util.List<SqlNode> operands)
Validates a COLUMN_LIST parametervoid
validateDataType(SqlDataTypeSpec dataType)
Validates a data type expression.private void
validateDefinitions(SqlMatchRecognize mr, MatchRecognizeScope scope)
void
validateDelete(SqlDelete call)
Validates a DELETE statement.void
validateDynamicParam(SqlDynamicParam dynamicParam)
Validates a dynamic parameter.private void
validateExpr(SqlNode expr, SqlValidatorScope scope)
Validates an expression.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.private void
validateGroupByItem(SqlSelect select, SqlNode groupByItem)
Validates an item in the GROUP BY clause of a SELECT statement.protected void
validateGroupClause(SqlSelect select)
Validates the GROUP BY clause of a SELECT statement.private void
validateGroupingSets(SqlValidatorScope groupScope, AggregatingSelectScope aggregatingScope, SqlCall groupItem)
private void
validateGroupItem(SqlValidatorScope groupScope, AggregatingSelectScope aggregatingScope, SqlNode groupItem)
protected void
validateHavingClause(SqlSelect select)
void
validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
Resolves an identifier to a fully-qualified name.void
validateInsert(SqlInsert insert)
Validates an INSERT statement.void
validateIntervalQualifier(SqlIntervalQualifier qualifier)
Validates aSqlIntervalQualifier
protected void
validateJoin(SqlJoin join, SqlValidatorScope scope)
void
validateLiteral(SqlLiteral literal)
Validates a literal.private void
validateLiteralAsDouble(SqlLiteral literal)
void
validateMatchRecognize(SqlCall call)
Validates a MATCH_RECOGNIZE clause.private java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>>
validateMeasure(SqlMatchRecognize mr, MatchRecognizeScope scope, boolean allRows)
void
validateMerge(SqlMerge call)
Validates a MERGE statement.private void
validateModality(SqlNode query)
Validates that a query can deliver the modality it promises.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.private void
validateNoAggs(AggFinder aggFinder, SqlNode node, java.lang.String clause)
Throws an error if there is an aggregate or windowed aggregate in the given clause.private void
validateNodeFeature(SqlNode node)
private void
validateOrderItem(SqlSelect select, SqlNode orderItem)
Validates an item in the ORDER BY clause of a SELECT statement.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, java.util.Map<java.lang.String,RelDataType> nameToTypeMap)
Validates an expression tree.void
validateQuery(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType)
Checks that a query is valid.private SqlNode
validateScopedExpression(SqlNode topNode, SqlValidatorScope scope)
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
validateUnnest(SqlCall call, SqlValidatorScope scope, RelDataType targetRowType)
void
validateUpdate(SqlUpdate call)
Validates an UPDATE statement.private RelDataType
validateUsingCol(SqlIdentifier id, SqlNode leftOrRight)
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, java.lang.String clause)
void
validateWindow(SqlNode windowOrId, SqlValidatorScope scope, 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)
-
-
-
Field Detail
-
TRACER
public static final org.slf4j.Logger TRACER
-
UPDATE_SRC_ALIAS
public static final java.lang.String UPDATE_SRC_ALIAS
Alias generated for the source table when rewriting UPDATE to MERGE.- See Also:
- Constant Field Values
-
UPDATE_TGT_ALIAS
public static final java.lang.String UPDATE_TGT_ALIAS
Alias generated for the target table when rewriting UPDATE to MERGE if no alias was specified by the user.- See Also:
- Constant Field Values
-
UPDATE_ANON_PREFIX
public static final java.lang.String UPDATE_ANON_PREFIX
Alias prefix generated for source columns when rewriting UPDATE to MERGE.- See Also:
- Constant Field Values
-
opTab
private final SqlOperatorTable opTab
-
catalogReader
final SqlValidatorCatalogReader catalogReader
-
idPositions
protected final java.util.Map<java.lang.String,SqlValidatorImpl.IdInfo> idPositions
Maps ParsePosition strings to theSqlIdentifier
identifier objects at these positions
-
scopes
protected final java.util.Map<SqlNode,SqlValidatorScope> scopes
Mapsquery node
objects to theSqlValidatorScope
scope created from them.
-
whereScopes
private final java.util.Map<SqlSelect,SqlValidatorScope> whereScopes
Maps aSqlSelect
node to the scope used by its WHERE and HAVING clauses.
-
groupByScopes
private final java.util.Map<SqlSelect,SqlValidatorScope> groupByScopes
Maps aSqlSelect
node to the scope used by its GROUP BY clause.
-
selectScopes
private final java.util.Map<SqlSelect,SqlValidatorScope> selectScopes
Maps aSqlSelect
node to the scope used by its SELECT and HAVING clauses.
-
orderScopes
private final java.util.Map<SqlSelect,SqlValidatorScope> orderScopes
Maps aSqlSelect
node to the scope used by its ORDER BY clause.
-
cursorScopes
private final java.util.Map<SqlSelect,SqlValidatorScope> cursorScopes
Maps aSqlSelect
node that is the argument to a CURSOR constructor to the scope of the result of that select node
-
tableScope
private TableScope tableScope
The name-resolution scope of a LATERAL TABLE clause.
-
namespaces
protected final java.util.Map<SqlNode,SqlValidatorNamespace> namespaces
-
cursorSet
private final java.util.Set<SqlNode> cursorSet
Set of select expressions used as cursor definitions. In standard SQL, only the top-level SELECT is a cursor; Calcite extends this with cursors as inputs to table functions.
-
functionCallStack
protected final java.util.Deque<SqlValidatorImpl.FunctionParamInfo> 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.
-
nextGeneratedId
private int nextGeneratedId
-
typeFactory
protected final RelDataTypeFactory typeFactory
-
unknownType
protected final RelDataType unknownType
The type of dynamic parameters until a type is imposed on them.
-
booleanType
private final RelDataType booleanType
-
nodeToTypeMap
private final java.util.Map<SqlNode,RelDataType> nodeToTypeMap
Map of derived RelDataType for each node. This is an IdentityHashMap since in some cases (such as null literals) we need to discriminate by instance.
-
aggFinder
private final AggFinder aggFinder
-
aggOrOverFinder
private final AggFinder aggOrOverFinder
-
aggOrOverOrGroupFinder
private final AggFinder aggOrOverOrGroupFinder
-
groupFinder
private final AggFinder groupFinder
-
overFinder
private final AggFinder overFinder
-
conformance
private final SqlConformance conformance
-
top
private SqlNode top
-
expandIdentifiers
protected boolean expandIdentifiers
-
expandColumnReferences
protected boolean expandColumnReferences
-
rewriteCalls
private boolean rewriteCalls
-
nullCollation
private NullCollation nullCollation
-
validatingSqlMerge
private boolean validatingSqlMerge
-
inWindow
private boolean inWindow
-
validationErrorFunction
private final SqlValidatorImpl.ValidationErrorFunction validationErrorFunction
-
-
Constructor Detail
-
SqlValidatorImpl
protected SqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance)
Creates a validator.- Parameters:
opTab
- Operator tablecatalogReader
- Catalog readertypeFactory
- Type factoryconformance
- Compatibility mode
-
-
Method Detail
-
getConformance
public SqlConformance getConformance()
Description copied from interface:SqlValidator
Returns the dialect of SQL (SQL:2003, etc.) this validator recognizes. Default isSqlConformanceEnum.DEFAULT
.- Specified by:
getConformance
in interfaceSqlValidator
- Returns:
- dialect of SQL this validator recognizes
-
getCatalogReader
public SqlValidatorCatalogReader getCatalogReader()
Description copied from interface:SqlValidator
Returns the catalog reader used by this validator.- Specified by:
getCatalogReader
in interfaceSqlValidator
- Returns:
- catalog reader
-
getOperatorTable
public SqlOperatorTable getOperatorTable()
Description copied from interface:SqlValidator
Returns the operator table used by this validator.- Specified by:
getOperatorTable
in interfaceSqlValidator
- Returns:
- operator table
-
getTypeFactory
public RelDataTypeFactory getTypeFactory()
Description copied from interface:SqlValidator
Returns the type factory used by this validator.- Specified by:
getTypeFactory
in interfaceSqlValidator
- Returns:
- type factory
-
getUnknownType
public RelDataType getUnknownType()
Description copied from interface:SqlValidator
Returns an object representing the "unknown" type.- Specified by:
getUnknownType
in interfaceSqlValidator
- Returns:
- unknown type
-
expandStar
public SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
Description copied from interface:SqlValidator
Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded.- Specified by:
expandStar
in interfaceSqlValidator
- Parameters:
selectList
- Select clause to be expandedselect
- QueryincludeSystemVars
- Whether to include system variables- Returns:
- expanded select clause
-
declareCursor
public void declareCursor(SqlSelect select, SqlValidatorScope parentScope)
Description copied from interface:SqlValidator
Declares a SELECT expression as a cursor.- Specified by:
declareCursor
in interfaceSqlValidator
- Parameters:
select
- select expression associated with the cursorparentScope
- scope of the parent query associated with the cursor
-
pushFunctionCall
public void pushFunctionCall()
Description copied from interface:SqlValidator
Pushes a new instance of a function call on to a function call stack.- Specified by:
pushFunctionCall
in interfaceSqlValidator
-
popFunctionCall
public void popFunctionCall()
Description copied from interface:SqlValidator
Removes the topmost entry from the function call stack.- Specified by:
popFunctionCall
in interfaceSqlValidator
-
getParentCursor
public java.lang.String getParentCursor(java.lang.String columnListParamName)
Description copied from interface:SqlValidator
Retrieves the name of the parent cursor referenced by a column list parameter.- Specified by:
getParentCursor
in interfaceSqlValidator
- Parameters:
columnListParamName
- name of the column list parameter- Returns:
- name of the parent cursor
-
expandSelectItem
private boolean expandSelectItem(SqlNode selectItem, SqlSelect select, RelDataType targetType, java.util.List<SqlNode> selectItems, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fields, boolean includeSystemVars)
IfselectItem
is "*" or "TABLE.*", expands it and returns true; otherwise writes the unexpanded item.- Parameters:
selectItem
- Select-list itemselect
- Containing select clauseselectItems
- List that expanded items are written toaliases
- Set of aliasesfields
- List of field names and types, in alias orderincludeSystemVars
- If true include system vars in lists- Returns:
- Whether the node was expanded
-
expandStar
private boolean expandStar(java.util.List<SqlNode> selectItems, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fields, boolean includeSystemVars, SelectScope scope, SqlNode node)
-
maybeCast
private SqlNode maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType)
-
addOrExpandField
private boolean addOrExpandField(java.util.List<SqlNode> selectItems, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fields, boolean includeSystemVars, SelectScope scope, SqlIdentifier id, RelDataTypeField field)
-
validate
public SqlNode validate(SqlNode topNode)
Description copied from interface:SqlValidator
Validates an expression tree. You can call this method multiple times, but not reentrantly.- Specified by:
validate
in interfaceSqlValidator
- Parameters:
topNode
- top of expression tree to be validated- Returns:
- validated tree (possibly rewritten)
-
lookupHints
public java.util.List<SqlMoniker> lookupHints(SqlNode topNode, SqlParserPos pos)
Description copied from interface:SqlValidatorWithHints
Looks up completion hints for a syntactically correct SQL statement that has been parsed into an expression tree. (Note this should be called afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)
.- Specified by:
lookupHints
in interfaceSqlValidatorWithHints
- Parameters:
topNode
- top of expression tree in which to lookup completion hintspos
- indicates the position in the sql statement we want to get completion hints for. For example, "select a.ename, b.deptno from sales.emp a join sales.dept b "on a.deptno=b.deptno where empno=1"; setting pos to 'Line 1, Column 17' returns all the possible column names that can be selected from sales.dept table setting pos to 'Line 1, Column 31' returns all the possible table names in 'sales' schema- Returns:
- an array of
SqlMoniker
(sql identifiers) that can fill in at the indicated position
-
lookupQualifiedName
public SqlMoniker lookupQualifiedName(SqlNode topNode, SqlParserPos pos)
Description copied from interface:SqlValidatorWithHints
Looks up the fully qualified name for aSqlIdentifier
at a given Parser Position in a parsed expression tree Note: call this only afterSqlValidator.validate(org.apache.calcite.sql.SqlNode)
has been called.- Specified by:
lookupQualifiedName
in interfaceSqlValidatorWithHints
- Parameters:
topNode
- top of expression tree in which to lookup the qualified name for the SqlIdentifierpos
- indicates the position of theSqlIdentifier
in the SQL statement we want to get the qualified name for- Returns:
- a string of the fully qualified name of the
SqlIdentifier
if the Parser position represents a validSqlIdentifier
. Else return an empty string
-
lookupSelectHints
void lookupSelectHints(SqlSelect select, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
Looks up completion hints for a syntactically correct select SQL that has been parsed into an expression tree.- Parameters:
select
- the Select node of the parsed expression treepos
- indicates the position in the sql statement we want to get completion hints forhintList
- list ofSqlMoniker
(sql identifiers) that can fill in at the indicated position
-
lookupSelectHints
private void lookupSelectHints(SqlValidatorNamespace ns, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
-
lookupFromHints
private void lookupFromHints(SqlNode node, SqlValidatorScope scope, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
-
lookupJoinHints
private void lookupJoinHints(SqlJoin join, SqlValidatorScope scope, SqlParserPos pos, java.util.Collection<SqlMoniker> hintList)
-
lookupNameCompletionHints
public final void lookupNameCompletionHints(SqlValidatorScope scope, java.util.List<java.lang.String> names, SqlParserPos pos, java.util.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
-
findAllValidUdfNames
private static void findAllValidUdfNames(java.util.List<java.lang.String> names, SqlValidator validator, java.util.Collection<SqlMoniker> result)
-
findAllValidFunctionNames
private static void findAllValidFunctionNames(java.util.List<java.lang.String> names, SqlValidator validator, java.util.Collection<SqlMoniker> result, SqlParserPos pos)
-
validateParameterizedExpression
public SqlNode validateParameterizedExpression(SqlNode topNode, java.util.Map<java.lang.String,RelDataType> nameToTypeMap)
Description copied from interface:SqlValidator
Validates an expression tree. You can call this method multiple times, but not reentrantly.- Specified by:
validateParameterizedExpression
in interfaceSqlValidator
- Parameters:
topNode
- top of expression tree to be validatednameToTypeMap
- map of simple name toRelDataType
; used to resolveSqlIdentifier
references- Returns:
- validated tree (possibly rewritten)
-
validateScopedExpression
private SqlNode validateScopedExpression(SqlNode topNode, SqlValidatorScope scope)
-
validateQuery
public void validateQuery(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType)
Description copied from interface:SqlValidator
Checks that a query is valid.Valid queries include:
SELECT
statement,- set operation (
UNION
,INTERSECT
,EXCEPT
) - identifier (e.g. representing use of a table in a FROM clause)
- query aliased with the
AS
operator
- Specified by:
validateQuery
in interfaceSqlValidator
- Parameters:
node
- Query nodescope
- Scope in which the query occurstargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
validateNamespace
protected void validateNamespace(SqlValidatorNamespace namespace, RelDataType targetRowType)
Validates a namespace.- Parameters:
namespace
- NamespacetargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
getEmptyScope
public SqlValidatorScope getEmptyScope()
-
getCursorScope
public SqlValidatorScope getCursorScope(SqlSelect select)
-
getWhereScope
public SqlValidatorScope getWhereScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns the scope that expressions in the WHERE and GROUP BY clause of this query should use. This scope consists of the tables in the FROM clause, and the enclosing scope.- Specified by:
getWhereScope
in interfaceSqlValidator
- Parameters:
select
- Query- Returns:
- naming scope of WHERE clause
-
getSelectScope
public SqlValidatorScope getSelectScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns the appropriate scope for validating a particular clause of a SELECT statement.Consider
SELECT * FROM foo WHERE EXISTS ( SELECT deptno AS x FROM emp JOIN dept ON emp.deptno = dept.deptno WHERE emp.deptno = 5 GROUP BY deptno ORDER BY x)
What objects can be seen in each part of the sub-query?
- In FROM (
SqlValidator.getFromScope(org.apache.calcite.sql.SqlSelect)
, you can only see 'foo'. - In WHERE (
SqlValidator.getWhereScope(org.apache.calcite.sql.SqlSelect)
), GROUP BY (SqlValidator.getGroupScope(org.apache.calcite.sql.SqlSelect)
), SELECT (getSelectScope
), and the ON clause of the JOIN (SqlValidator.getJoinScope(org.apache.calcite.sql.SqlNode)
) you can see 'emp', 'dept', and 'foo'. - In ORDER BY (
SqlValidator.getOrderScope(org.apache.calcite.sql.SqlSelect)
), you can see the column alias 'x'; and tables 'emp', 'dept', and 'foo'.
- Specified by:
getSelectScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for SELECT statement
- In FROM (
-
getRawSelectScope
public SelectScope getRawSelectScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns the scope for resolving the SELECT, GROUP BY and HAVING clauses. Always aSelectScope
; if this is an aggregation query, theAggregatingScope
is stripped away.- Specified by:
getRawSelectScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for SELECT statement, sans any aggregating scope
-
getHavingScope
public SqlValidatorScope getHavingScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the HAVING clause of a query.- Specified by:
getHavingScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for HAVING clause
-
getGroupScope
public SqlValidatorScope getGroupScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the GROUP BY clause of a query.- Specified by:
getGroupScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for GROUP BY clause
-
getFromScope
public SqlValidatorScope getFromScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the FROM clause of a query.- Specified by:
getFromScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for FROM clause
-
getOrderScope
public SqlValidatorScope getOrderScope(SqlSelect select)
Description copied from interface:SqlValidator
Returns the scope that expressions in the SELECT and HAVING clause of this query should use. This scope consists of the FROM clause and the enclosing scope. If the query is aggregating, only columns in the GROUP BY clause may be used.- Specified by:
getOrderScope
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- naming scope for ORDER BY clause
-
getMatchRecognizeScope
public SqlValidatorScope getMatchRecognizeScope(SqlMatchRecognize node)
Description copied from interface:SqlValidator
Returns a scope match recognize clause.- Specified by:
getMatchRecognizeScope
in interfaceSqlValidator
- Parameters:
node
- Match recognize- Returns:
- naming scope for Match recognize clause
-
getJoinScope
public SqlValidatorScope getJoinScope(SqlNode node)
Description copied from interface:SqlValidator
Returns a scope containing the objects visible from the ON and USING sections of a JOIN clause.- Specified by:
getJoinScope
in interfaceSqlValidator
- Parameters:
node
- The item in the FROM clause which contains the ON or USING expression- Returns:
- naming scope for JOIN clause
- See Also:
SqlValidator.getFromScope(org.apache.calcite.sql.SqlSelect)
-
getOverScope
public SqlValidatorScope getOverScope(SqlNode node)
Description copied from interface:SqlValidator
Returns the scope of an OVER or VALUES node.- Specified by:
getOverScope
in interfaceSqlValidator
- Parameters:
node
- Node- Returns:
- Scope
-
getNamespace
private SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
-
getNamespace
private SqlValidatorNamespace getNamespace(SqlIdentifier id, DelegatingScope scope)
-
getNamespace
public SqlValidatorNamespace getNamespace(SqlNode node)
Description copied from interface:SqlValidator
Finds the namespace corresponding to a given node.For example, in the query
SELECT * FROM (SELECT * FROM t), t1 AS alias
, the both items in the FROM clause have a corresponding namespace.- Specified by:
getNamespace
in interfaceSqlValidator
- Parameters:
node
- Parse tree node- Returns:
- namespace of node
-
performUnconditionalRewrites
protected SqlNode performUnconditionalRewrites(SqlNode node, boolean underFrom)
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.- Parameters:
node
- expression to be rewrittenunderFrom
- whether node appears directly under a FROM clause- Returns:
- rewritten expression
-
rewriteMerge
private void rewriteMerge(SqlMerge call)
-
rewriteUpdateToMerge
private SqlNode rewriteUpdateToMerge(SqlUpdate updateCall, SqlNode selfJoinSrcExpr)
-
getSelfJoinExprForUpdate
protected SqlNode getSelfJoinExprForUpdate(SqlNode table, java.lang.String alias)
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
protected SqlSelect createSourceSelectForUpdate(SqlUpdate call)
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
protected SqlSelect createSourceSelectForDelete(SqlDelete call)
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
-
getTableConstructorRowType
RelDataType getTableConstructorRowType(SqlCall values, SqlValidatorScope scope)
Returns null if there is no common type. E.g. if the rows have a different number of columns.
-
getValidatedNodeType
public RelDataType getValidatedNodeType(SqlNode node)
Description copied from interface:SqlValidator
Returns the type assigned to a node by validation.- Specified by:
getValidatedNodeType
in interfaceSqlValidator
- Parameters:
node
- the node of interest- Returns:
- validated type, never null
-
getValidatedNodeTypeIfKnown
public RelDataType getValidatedNodeTypeIfKnown(SqlNode node)
Description copied from interface:SqlValidator
Returns the type assigned to a node by validation, or null if unknown. This allows for queries against nodes such as aliases, which have no type of their own. If you want to assert that the node of interest must have a type, useSqlValidator.getValidatedNodeType(org.apache.calcite.sql.SqlNode)
instead.- Specified by:
getValidatedNodeTypeIfKnown
in interfaceSqlValidator
- Parameters:
node
- the node of interest- Returns:
- validated type, or null if unknown or not applicable
-
setValidatedNodeType
public final void setValidatedNodeType(SqlNode node, RelDataType type)
Saves the type of aSqlNode
, now that it has been validated.Unlike the base class method, this method is not deprecated. It is available from within Calcite, but is not part of the public API.
- Specified by:
setValidatedNodeType
in interfaceSqlValidator
- Parameters:
node
- A SQL parse tree node, never nulltype
- Its type; must not be null
-
removeValidatedNodeType
public void removeValidatedNodeType(SqlNode node)
Description copied from interface:SqlValidator
Removes a node from the set of validated nodes- Specified by:
removeValidatedNodeType
in interfaceSqlValidator
- Parameters:
node
- node to be removed
-
deriveType
public RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
Description copied from interface:SqlValidator
Derives the type of a node in a given scope. If the type has already been inferred, returns the previous type.- Specified by:
deriveType
in interfaceSqlValidator
- Parameters:
scope
- Syntactic scopeexpr
- Parse tree node- Returns:
- Type of the SqlNode. Should never return
NULL
-
deriveTypeImpl
RelDataType deriveTypeImpl(SqlValidatorScope scope, SqlNode operand)
Derives the type of a node, never null.
-
deriveConstructorType
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, java.util.List<RelDataType> argTypes)
Description copied from interface:SqlValidator
Derives the type of a constructor.- Specified by:
deriveConstructorType
in interfaceSqlValidator
- Parameters:
scope
- Scopecall
- CallunresolvedConstructor
- TODOresolvedConstructor
- TODOargTypes
- Types of arguments- Returns:
- Resolved type of constructor
-
handleUnresolvedFunction
public CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, java.util.List<RelDataType> argTypes, java.util.List<java.lang.String> argNames)
Description copied from interface:SqlValidator
Handles a call to a function which cannot be resolved. Returns a an appropriately descriptive error, which caller must throw.- Specified by:
handleUnresolvedFunction
in interfaceSqlValidator
- Parameters:
call
- CallunresolvedFunction
- Overloaded function which is the target of the callargTypes
- Types of argumentsargNames
- Names of arguments, or null if call by position
-
inferUnknownTypes
protected void inferUnknownTypes(@Nonnull RelDataType inferredType, @Nonnull SqlValidatorScope scope, @Nonnull SqlNode node)
-
addToSelectList
protected void addToSelectList(java.util.List<SqlNode> list, java.util.Set<java.lang.String> aliases, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fieldList, SqlNode exp, SqlValidatorScope 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
public java.lang.String deriveAlias(SqlNode node, int ordinal)
Description copied from interface:SqlValidator
Derives an alias for an expression. If no alias can be derived, returns null ifordinal
is less than zero, otherwise generates an aliasEXPR$ordinal
.- Specified by:
deriveAlias
in interfaceSqlValidator
- Parameters:
node
- Expressionordinal
- Ordinal of expression- Returns:
- derived alias, or null if no alias can be derived and ordinal is less than zero
-
setIdentifierExpansion
public void setIdentifierExpansion(boolean expandIdentifiers)
Description copied from interface:SqlValidator
Enables or disables expansion of identifiers other than column references.- Specified by:
setIdentifierExpansion
in interfaceSqlValidator
- Parameters:
expandIdentifiers
- new setting
-
setColumnReferenceExpansion
public void setColumnReferenceExpansion(boolean expandColumnReferences)
Description copied from interface:SqlValidator
Enables or disables expansion of column references. (Currently this does not apply to the ORDER BY clause; may be fixed in the future.)- Specified by:
setColumnReferenceExpansion
in interfaceSqlValidator
- Parameters:
expandColumnReferences
- new setting
-
getColumnReferenceExpansion
public boolean getColumnReferenceExpansion()
- Specified by:
getColumnReferenceExpansion
in interfaceSqlValidator
- Returns:
- whether column reference expansion is enabled
-
setDefaultNullCollation
public void setDefaultNullCollation(NullCollation nullCollation)
Description copied from interface:SqlValidator
Sets how NULL values should be collated if an ORDER BY item does not contain NULLS FIRST or NULLS LAST.- Specified by:
setDefaultNullCollation
in interfaceSqlValidator
-
getDefaultNullCollation
public NullCollation getDefaultNullCollation()
Description copied from interface:SqlValidator
Returns how NULL values should be collated if an ORDER BY item does not contain NULLS FIRST or NULLS LAST.- Specified by:
getDefaultNullCollation
in interfaceSqlValidator
-
setCallRewrite
public void setCallRewrite(boolean rewriteCalls)
Description copied from interface:SqlValidator
Enables or disables rewrite of "macro-like" calls such as COALESCE.- Specified by:
setCallRewrite
in interfaceSqlValidator
- Parameters:
rewriteCalls
- new setting
-
shouldExpandIdentifiers
public boolean shouldExpandIdentifiers()
Description copied from interface:SqlValidator
Returns expansion of identifiers.- Specified by:
shouldExpandIdentifiers
in interfaceSqlValidator
- Returns:
- whether this validator should expand identifiers
-
shouldAllowIntermediateOrderBy
protected boolean shouldAllowIntermediateOrderBy()
-
registerMatchRecognize
private void registerMatchRecognize(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlMatchRecognize call, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable)
-
createMatchRecognizeNameSpace
protected MatchRecognizeNamespace createMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode)
-
registerNamespace
protected void registerNamespace(SqlValidatorScope usingScope, java.lang.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
-
registerFrom
private SqlNode registerFrom(SqlValidatorScope parentScope, SqlValidatorScope usingScope, boolean register, SqlNode node, SqlNode enclosingNode, java.lang.String alias, SqlNodeList extendList, boolean forceNullable, boolean lateral)
Registers scopes and namespaces implied a relational expression in the FROM clause.parentScope
andusingScope
are often the same. They differ when the namespace are not visible within the parent. (Example needed.)Likewise,
enclosingNode
andnode
are often the same.enclosingNode
is the topmost node within the FROM clause, from which any decorations like an alias (AS alias
) or a table sample clause are stripped away to getnode
. Both are recorded in the namespace.- Parameters:
parentScope
- Parent scope which this scope turns to in order to resolve objectsusingScope
- Scope whose child list this scope should add itself toregister
- Whether to register this scope as a child ofusingScope
node
- Node which namespace is based onenclosingNode
- Outermost node for namespace, including decorations such as alias and sample clausealias
- AliasextendList
- Definitions of extended columnsforceNullable
- Whether to force the type of namespace to be nullable because it is in an outer joinlateral
- Whether LATERAL is specified, so that items to the left of this in the JOIN tree are visible in the scope- Returns:
- registered node, usually the same as
node
-
isLateral
private static boolean isLateral(SqlNode node)
-
shouldAllowOverRelation
protected boolean shouldAllowOverRelation()
-
createSelectNamespace
protected SelectNamespace createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
Creates a namespace for aSELECT
node. Derived class may override this factory method.- Parameters:
select
- Select nodeenclosingNode
- Enclosing node- Returns:
- Select namespace
-
createSetopNamespace
protected SetopNamespace createSetopNamespace(SqlCall call, SqlNode enclosingNode)
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
private void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, java.lang.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
-
registerQuery
private void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable, boolean checkUpdate)
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 != nullcheckUpdate
- if true, validate that the update feature is supported if validating the update statement
-
registerSetop
private void registerSetop(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable)
-
registerWith
private void registerWith(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlWith with, SqlNode enclosingNode, java.lang.String alias, boolean forceNullable, boolean checkUpdate)
-
isAggregate
public boolean isAggregate(SqlSelect select)
Description copied from interface:SqlValidator
Returns whether a SELECT statement is an aggregation. Criteria are: (1) contains GROUP BY, or (2) contains HAVING, or (3) SELECT or ORDER BY clause contains aggregate functions. (Windowed aggregate functions, such asSUM(x) OVER w
, don't count.)- Specified by:
isAggregate
in interfaceSqlValidator
- Parameters:
select
- SELECT statement- Returns:
- whether SELECT statement is an aggregation
-
isNestedAggregateWindow
protected boolean isNestedAggregateWindow(SqlNode node)
-
isOverAggregateWindow
protected boolean isOverAggregateWindow(SqlNode node)
-
getAggregate
protected SqlNode getAggregate(SqlSelect select)
Returns the parse tree node (GROUP BY, HAVING, or an aggregate function call) that causesselect
to be an aggregate query, or null if it is not an aggregate query.The node is useful context for error messages, but you cannot assume that the node is the only aggregate function.
-
getAgg
private SqlNode getAgg(SqlSelect select)
If there is at least one call to an aggregate function, returns the first.
-
isAggregate
public boolean isAggregate(SqlNode selectNode)
Description copied from interface:SqlValidator
Returns whether a select list expression is an aggregate function.- Specified by:
isAggregate
in interfaceSqlValidator
- Parameters:
selectNode
- Expression in SELECT clause- Returns:
- whether expression is an aggregate function
-
validateNodeFeature
private void validateNodeFeature(SqlNode node)
-
registerSubQueries
private void registerSubQueries(SqlValidatorScope parentScope, SqlNode node)
-
registerOperandSubQueries
private void registerOperandSubQueries(SqlValidatorScope parentScope, SqlCall call, int operandOrdinal)
Registers any sub-queries inside a given call operand, and converts the operand to a scalar sub-query if the operator requires it.- Parameters:
parentScope
- Parent scopecall
- CalloperandOrdinal
- Ordinal of operand within call- See Also:
SqlOperator.argumentMustBeScalar(int)
-
validateIdentifier
public void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
Description copied from interface:SqlValidator
Resolves an identifier to a fully-qualified name.- Specified by:
validateIdentifier
in interfaceSqlValidator
- Parameters:
id
- Identifierscope
- Naming scope
-
validateLiteral
public void validateLiteral(SqlLiteral literal)
Description copied from interface:SqlValidator
Validates a literal.- Specified by:
validateLiteral
in interfaceSqlValidator
- Parameters:
literal
- Literal
-
validateLiteralAsDouble
private void validateLiteralAsDouble(SqlLiteral literal)
-
validateIntervalQualifier
public void validateIntervalQualifier(SqlIntervalQualifier qualifier)
Description copied from interface:SqlValidator
Validates aSqlIntervalQualifier
- Specified by:
validateIntervalQualifier
in interfaceSqlValidator
- Parameters:
qualifier
- Interval qualifier
-
validateFrom
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.- Parameters:
node
- Node in FROM clause, typically a table or derived tabletargetRowType
- Desired row type of this expression, orunknownType
if not fussy. Must not be null.scope
- Scope
-
validateOver
protected void validateOver(SqlCall call, SqlValidatorScope scope)
-
validateUnnest
protected void validateUnnest(SqlCall call, SqlValidatorScope scope, RelDataType targetRowType)
-
checkRollUpInUsing
private void checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight)
-
validateJoin
protected void validateJoin(SqlJoin join, SqlValidatorScope scope)
-
validateNoAggs
private void validateNoAggs(AggFinder aggFinder, SqlNode node, java.lang.String clause)
Throws an error if there is an aggregate or windowed aggregate in the given clause.- Parameters:
aggFinder
- Finder for the particular kind(s) of aggregate functionnode
- Parse treeclause
- Name of clause: "WHERE", "GROUP BY", "ON"
-
validateUsingCol
private RelDataType validateUsingCol(SqlIdentifier id, SqlNode leftOrRight)
-
validateSelect
protected void validateSelect(SqlSelect select, RelDataType targetRowType)
Validates a SELECT statement.- Parameters:
select
- Select statementtargetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
checkRollUpInSelectList
private void checkRollUpInSelectList(SqlSelect select)
-
checkRollUpInGroupBy
private void checkRollUpInGroupBy(SqlSelect select)
-
checkRollUpInOrderBy
private void checkRollUpInOrderBy(SqlSelect select)
-
checkRollUpInWindow
private void checkRollUpInWindow(SqlWindow window, SqlValidatorScope scope)
-
checkRollUpInWindowDecl
private void checkRollUpInWindowDecl(SqlSelect select)
-
checkRollUp
private void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, java.lang.String optionalClause)
-
checkRollUp
private void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope)
-
findTableColumnPair
private Pair<java.lang.String,java.lang.String> findTableColumnPair(SqlIdentifier identifier, SqlValidatorScope scope)
-
isRolledUpColumnAllowedInAgg
private boolean isRolledUpColumnAllowedInAgg(SqlIdentifier identifier, SqlValidatorScope scope, SqlCall aggCall, SqlNode parent)
-
isRolledUpColumn
private boolean isRolledUpColumn(SqlIdentifier identifier, SqlValidatorScope scope)
-
findTable
private Table findTable(CalciteSchema schema, java.lang.String tableName, boolean caseSensitive)
-
findTable
private Table findTable(java.lang.String alias)
Given a table alias, find the correspondingTable
associated with it
-
shouldCheckForRollUp
private boolean shouldCheckForRollUp(SqlNode from)
-
validateModality
private void validateModality(SqlNode query)
Validates that a query can deliver the modality it promises. Only called on the top-most SELECT or set operator in the tree.
-
deduceModality
private SqlModality deduceModality(SqlNode query)
Return the intended modality of a SELECT or set-op.
-
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
- 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
-
hasSortedPrefix
private boolean hasSortedPrefix(SelectScope scope, SqlNodeList orderList)
Returns whether the prefix is sorted.
-
isSortCompatible
private boolean isSortCompatible(SelectScope scope, SqlNode node, boolean descending)
-
validateWindowClause
protected void validateWindowClause(SqlSelect select)
-
validateWith
public void validateWith(SqlWith with, SqlValidatorScope scope)
- Specified by:
validateWith
in interfaceSqlValidator
-
validateWithItem
public void validateWithItem(SqlWithItem withItem)
- Specified by:
validateWithItem
in interfaceSqlValidator
-
validateSequenceValue
public void validateSequenceValue(SqlValidatorScope scope, SqlIdentifier id)
- Specified by:
validateSequenceValue
in interfaceSqlValidator
-
getWithScope
public SqlValidatorScope getWithScope(SqlNode withItem)
- Specified by:
getWithScope
in interfaceSqlValidator
-
validateOrderList
protected void validateOrderList(SqlSelect select)
Validates the ORDER BY clause of a SELECT statement.- Parameters:
select
- Select statement
-
validateGroupByItem
private void validateGroupByItem(SqlSelect select, SqlNode groupByItem)
Validates an item in the GROUP BY clause of a SELECT statement.- Parameters:
select
- Select statementgroupByItem
- GROUP BY clause item
-
validateOrderItem
private void validateOrderItem(SqlSelect select, SqlNode orderItem)
Validates an item in the ORDER BY clause of a SELECT statement.- Parameters:
select
- Select statementorderItem
- ORDER BY clause item
-
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
- Parameters:
select
- Select statement which contains ORDER BYorderExpr
- Expression in the ORDER BY clause.- Returns:
- Expression translated into SELECT clause semantics
-
validateGroupClause
protected void validateGroupClause(SqlSelect select)
Validates the GROUP BY clause of a SELECT statement. This method is called even if no GROUP BY clause is present.
-
validateGroupItem
private void validateGroupItem(SqlValidatorScope groupScope, AggregatingSelectScope aggregatingScope, SqlNode groupItem)
-
validateGroupingSets
private void validateGroupingSets(SqlValidatorScope groupScope, AggregatingSelectScope aggregatingScope, SqlCall groupItem)
-
validateWhereClause
protected void validateWhereClause(SqlSelect select)
-
validateWhereOrOn
protected void validateWhereOrOn(SqlValidatorScope scope, SqlNode condition, java.lang.String clause)
-
validateHavingClause
protected void validateHavingClause(SqlSelect select)
-
validateSelectList
protected RelDataType validateSelectList(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType)
-
validateExpr
private void validateExpr(SqlNode expr, SqlValidatorScope scope)
Validates an expression.- Parameters:
expr
- Expressionscope
- Scope in which expression occurs
-
handleScalarSubQuery
private void handleScalarSubQuery(SqlSelect parentSelect, SqlSelect selectItem, java.util.List<SqlNode> expandedSelectItems, java.util.Set<java.lang.String> aliasList, java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> fieldList)
Processes SubQuery found in Select list. Checks that is actually Scalar sub-query and makes proper entries in each of the 3 lists used to create the final rowType entry.- Parameters:
parentSelect
- base SqlSelect itemselectItem
- child SqlSelect from select listexpandedSelectItems
- Select items after processingaliasList
- built from user or system valuesfieldList
- Built up entries for each select list entry
-
createTargetRowType
protected RelDataType createTargetRowType(SqlValidatorTable table, SqlNodeList targetColumnList, boolean append)
Derives a row-type for INSERT and UPDATE operations.- Parameters:
table
- Target table for INSERT/UPDATEtargetColumnList
- List of target columns, or null if not specifiedappend
- Whether to append fields to those inbaseRowType
- Returns:
- Rowtype
-
validateInsert
public void validateInsert(SqlInsert insert)
Description copied from interface:SqlValidator
Validates an INSERT statement.- Specified by:
validateInsert
in interfaceSqlValidator
- Parameters:
insert
- INSERT statement
-
checkConstraint
private void checkConstraint(SqlValidatorTable validatorTable, SqlNode source, RelDataType targetRowType)
Validates insert values against the constraint of a modifiable view.- Parameters:
validatorTable
- Table that may wrap a ModifiableViewTablesource
- The values being insertedtargetRowType
- The target type for the view
-
checkConstraint
private void checkConstraint(SqlValidatorTable validatorTable, SqlUpdate update, RelDataType targetRowType)
Validates updates against the constraint of a modifiable view.- Parameters:
validatorTable
- ASqlValidatorTable
that may wrap a ModifiableViewTableupdate
- The UPDATE parse tree nodetargetRowType
- The target type
-
checkFieldCount
private void checkFieldCount(SqlNode node, SqlValidatorTable table, SqlNode source, RelDataType logicalSourceRowType, RelDataType logicalTargetRowType)
-
isValuesWithDefault
private boolean isValuesWithDefault(SqlNode source, int column)
Returns whether a query usesDEFAULT
to populate a given column.
-
isRowWithDefault
private boolean isRowWithDefault(SqlNode operand, int column)
-
getLogicalTargetRowType
protected RelDataType getLogicalTargetRowType(RelDataType targetRowType, SqlInsert insert)
-
getLogicalSourceRowType
protected RelDataType getLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert)
-
checkTypeAssignment
protected void checkTypeAssignment(RelDataType sourceRowType, RelDataType targetRowType, SqlNode query)
-
getNthExpr
private SqlNode getNthExpr(SqlNode query, int ordinal, int sourceCount)
Locates the n'th expression in an INSERT or UPDATE query.- Parameters:
query
- Queryordinal
- Ordinal of expressionsourceCount
- Number of expressions- Returns:
- Ordinal'th expression, never null
-
validateDelete
public void validateDelete(SqlDelete call)
Description copied from interface:SqlValidator
Validates a DELETE statement.- Specified by:
validateDelete
in interfaceSqlValidator
- Parameters:
call
- DELETE statement
-
validateUpdate
public void validateUpdate(SqlUpdate call)
Description copied from interface:SqlValidator
Validates an UPDATE statement.- Specified by:
validateUpdate
in interfaceSqlValidator
- Parameters:
call
- UPDATE statement
-
validateMerge
public void validateMerge(SqlMerge call)
Description copied from interface:SqlValidator
Validates a MERGE statement.- Specified by:
validateMerge
in interfaceSqlValidator
- Parameters:
call
- MERGE statement
-
validateAccess
private void validateAccess(SqlNode node, SqlValidatorTable table, SqlAccessEnum requiredAccess)
Validates access to a table.- Parameters:
table
- TablerequiredAccess
- Access requested on table
-
validateValues
protected void validateValues(SqlCall node, RelDataType targetRowType, SqlValidatorScope scope)
Validates a VALUES clause.- Parameters:
node
- Values clausetargetRowType
- Row type which expression must conform toscope
- Scope within which clause occurs
-
validateDataType
public void validateDataType(SqlDataTypeSpec dataType)
Description copied from interface:SqlValidator
Validates a data type expression.- Specified by:
validateDataType
in interfaceSqlValidator
- Parameters:
dataType
- Data type
-
validateDynamicParam
public void validateDynamicParam(SqlDynamicParam dynamicParam)
Description copied from interface:SqlValidator
Validates a dynamic parameter.- Specified by:
validateDynamicParam
in interfaceSqlValidator
- Parameters:
dynamicParam
- Dynamic parameter
-
getValidationErrorFunction
public SqlValidatorImpl.ValidationErrorFunction getValidationErrorFunction()
-
newValidationError
public CalciteContextException newValidationError(SqlNode node, Resources.ExInst<SqlValidatorException> e)
Description copied from interface:SqlValidator
Adds "line x, column y" context to a validator exception.Note that the input exception is checked (it derives from
Exception
) and the output exception is unchecked (it derives fromRuntimeException
). This is intentional -- it should remind code authors to provide context for their validation errors.- Specified by:
newValidationError
in interfaceSqlValidator
- Parameters:
node
- The place where the exception occurred, not nulle
- The validation error- Returns:
- Exception containing positional information, never null
-
getWindowByName
protected SqlWindow getWindowByName(SqlIdentifier id, SqlValidatorScope scope)
-
resolveWindow
public SqlWindow resolveWindow(SqlNode windowOrRef, SqlValidatorScope scope, boolean populateBounds)
Description copied from interface:SqlValidator
Converts a window specification or window name into a fully-resolved window specification. For example, inSELECT sum(x) OVER (PARTITION BY x ORDER BY y), sum(y) OVER w1, sum(z) OVER (w ORDER BY y) FROM t WINDOW w AS (PARTITION BY x)
all aggregations have the same resolved window specification(PARTITION BY x ORDER BY y)
.- Specified by:
resolveWindow
in interfaceSqlValidator
- Parameters:
windowOrRef
- Either the name of a window (aSqlIdentifier
) or a window specification (aSqlWindow
).scope
- Scope in which to resolve window namespopulateBounds
- Whether to populate bounds. Doing so may alter the definition of the window. It is recommended that populate bounds when translating to physical algebra, but not when validating.- Returns:
- A window
-
lookupFieldNamespace
SqlValidatorNamespace lookupFieldNamespace(RelDataType rowType, java.lang.String name)
-
validateWindow
public void validateWindow(SqlNode windowOrId, SqlValidatorScope scope, SqlCall call)
Description copied from interface:SqlValidator
Validates the right-hand side of an OVER expression. It might be either anidentifier
referencing a window, or aninline window specification
.- Specified by:
validateWindow
in interfaceSqlValidator
- Parameters:
windowOrId
- SqlNode that can be either SqlWindow with all the components of a window spec or a SqlIdentifier with the name of a window spec.scope
- Naming scopecall
- the SqlNode if a function call if the window is attached to one.
-
validateMatchRecognize
public void validateMatchRecognize(SqlCall call)
Description copied from interface:SqlValidator
Validates a MATCH_RECOGNIZE clause.- Specified by:
validateMatchRecognize
in interfaceSqlValidator
- Parameters:
call
- MATCH_RECOGNIZE clause
-
validateMeasure
private java.util.List<java.util.Map.Entry<java.lang.String,RelDataType>> validateMeasure(SqlMatchRecognize mr, MatchRecognizeScope scope, boolean allRows)
-
validateDefinitions
private void validateDefinitions(SqlMatchRecognize mr, MatchRecognizeScope scope)
-
alias
private static java.lang.String alias(SqlNode item)
Returns the alias of a "expr AS alias" expression.
-
navigationInDefine
private SqlNode navigationInDefine(SqlNode node, java.lang.String alpha)
Checks that all pattern variables within a function are the same, and canonizes expressions such asPREV(B.price)
toLAST(B.price, 0)
.
-
validateAggregateParams
public void validateAggregateParams(SqlCall aggCall, SqlNode filter, SqlNodeList orderList, SqlValidatorScope scope)
Description copied from interface:SqlValidator
Validates parameters for aggregate function.- Specified by:
validateAggregateParams
in interfaceSqlValidator
- Parameters:
aggCall
- Call to aggregate functionfilter
- Filter (FILTER (WHERE)
clause), or nullorderList
- Ordering specification (WITHING GROUP
clause), or nullscope
- Syntactic scope
-
validateCall
public void validateCall(SqlCall call, SqlValidatorScope scope)
Description copied from interface:SqlValidator
Validates a call to an operator.- Specified by:
validateCall
in interfaceSqlValidator
- Parameters:
call
- Operator callscope
- Naming scope
-
validateFeature
protected void validateFeature(Feature feature, SqlParserPos context)
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
-
expand
public SqlNode expand(SqlNode expr, SqlValidatorScope scope)
Description copied from interface:SqlValidator
Expands an expression.- Specified by:
expand
in interfaceSqlValidator
- Parameters:
expr
- Expressionscope
- Scope- Returns:
- Expanded expression
-
expandGroupByOrHavingExpr
public SqlNode expandGroupByOrHavingExpr(SqlNode expr, SqlValidatorScope scope, SqlSelect select, boolean havingExpression)
-
isSystemField
public boolean isSystemField(RelDataTypeField field)
Description copied from interface:SqlValidator
Returns whether a field is a system field. Such fields may have particular properties such as sortedness and nullability.In the default implementation, always returns
false
.- Specified by:
isSystemField
in interfaceSqlValidator
- Parameters:
field
- Field- Returns:
- whether field is a system field
-
getFieldOrigins
public java.util.List<java.util.List<java.lang.String>> getFieldOrigins(SqlNode sqlQuery)
Description copied from interface:SqlValidator
Returns a description of how each field in the row type maps to a catalog, schema, table and column in the schema.The returned list is never null, and has one element for each field in the row type. Each element is a list of four elements (catalog, schema, table, column), or may be null if the column is an expression.
- Specified by:
getFieldOrigins
in interfaceSqlValidator
- Parameters:
sqlQuery
- Query- Returns:
- Description of how each field in the row type maps to a schema object
-
getFieldOrigin
private java.util.List<java.lang.String> getFieldOrigin(SqlNode sqlQuery, int i)
-
getParameterRowType
public RelDataType getParameterRowType(SqlNode sqlQuery)
Description copied from interface:SqlValidator
Returns a record type that contains the name and type of each parameter. Returns a record type with no fields if there are no parameters.- Specified by:
getParameterRowType
in interfaceSqlValidator
- Parameters:
sqlQuery
- Query- Returns:
- Record type
-
validateColumnListParams
public void validateColumnListParams(SqlFunction function, java.util.List<RelDataType> argTypes, java.util.List<SqlNode> operands)
Description copied from interface:SqlValidator
Validates a COLUMN_LIST parameter- Specified by:
validateColumnListParams
in interfaceSqlValidator
- Parameters:
function
- function containing COLUMN_LIST parameterargTypes
- function argumentsoperands
- operands passed into the function call
-
isPhysicalNavigation
private static boolean isPhysicalNavigation(SqlKind kind)
-
isLogicalNavigation
private static boolean isLogicalNavigation(SqlKind kind)
-
isAggregation
private static boolean isAggregation(SqlKind kind)
-
isRunningOrFinal
private static boolean isRunningOrFinal(SqlKind kind)
-
isSingleVarRequired
private static boolean isSingleVarRequired(SqlKind kind)
-
-