Interface SqlValidatorScope
- All Known Subinterfaces:
AggregatingScope
- All Known Implementing Classes:
AggregatingSelectScope
,DelegatingScope
,GroupByScope
,JoinScope
,ListScope
,MatchRecognizeScope
,MeasureScope
,OrderByScope
,OverScope
,ParameterScope
,PivotScope
,SelectScope
,SqlLambdaScope
,UnpivotScope
When validating an expression, say "foo"."bar", you first use the
resolve(java.util.List<java.lang.String>, org.apache.calcite.sql.validate.SqlNameMatcher, boolean, org.apache.calcite.sql.validate.SqlValidatorScope.Resolved)
method of the scope where the expression is defined to
locate "foo". If successful, this returns a
namespace
describing the type of the resulting
object.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A path that has no steps.static class
A sequence of steps by which an identifier was resolved.static class
A match found when looking up a name.static interface
static class
Default implementation ofSqlValidatorScope.Resolved
.static class
A step in resolving an identifier. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(SqlValidatorNamespace ns, String alias, boolean nullable) Registers a relation in this scope.void
findAliases
(Collection<SqlMoniker> result) Collects theSqlMoniker
s of all table aliases (uses of tables in query FROM clauses) available in this scope.void
findAllColumnNames
(List<SqlMoniker> result) Collects theSqlMoniker
s of all possible columns in this scope.findQualifyingTableName
(String columnName, SqlNode ctx) Deprecated.findQualifyingTableNames
(String columnName, SqlNode ctx, SqlNameMatcher nameMatcher) Finds all table aliases which are implicitly qualifying an unqualified column name.fullyQualify
(SqlIdentifier identifier) Converts an identifier into a fully-qualified identifier.getMonotonicity
(SqlNode expr) Returns whether an expression is monotonic in this scope.getNode()
Returns the root node of this scope.getOperandScope
(SqlCall call) Returns the scope within which operands to a call are to be validated.@Nullable SqlNodeList
Returns the expressions by which the rows in this scope are sorted.@Nullable SqlValidatorNamespace
getTableNamespace
(List<String> names) Deprecated.Returns the validator which created this scope.default boolean
isMeasureRef
(SqlNode node) Returns whether an expression is a reference to a measure column.default boolean
isWithin
(SqlValidatorScope scope2) Returns whether this scope is enclosed withinscope2
in such a way that it can see the contents ofscope2
.@Nullable SqlWindow
lookupWindow
(String name) Finds a window with a given name.nullifyType
(SqlNode node, RelDataType type) Converts the type of an expression to nullable, if the context warrants it.void
resolve
(List<String> names, SqlNameMatcher nameMatcher, boolean deep, SqlValidatorScope.Resolved resolved) Looks up a node with a given name.@Nullable RelDataType
resolveColumn
(String name, SqlNode ctx) Resolves a single identifier to a column, and returns the datatype of that column.void
resolveTable
(List<String> names, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved) Looks up a table in this scope from its name.void
validateExpr
(SqlNode expr) Performs any scope-specific validation of an expression.
-
Method Details
-
getValidator
SqlValidator getValidator()Returns the validator which created this scope. -
getNode
SqlNode getNode()Returns the root node of this scope. Never null. -
resolve
void resolve(List<String> names, SqlNameMatcher nameMatcher, boolean deep, SqlValidatorScope.Resolved resolved) Looks up a node with a given name. Returns null if none is found.- Parameters:
names
- Name of node to find, maybe partially or fully qualifiednameMatcher
- Name matcherdeep
- Whether to look more than one level deepresolved
- Callback wherein to write the match(es) we find
-
findQualifyingTableName
@Deprecated Pair<String,SqlValidatorNamespace> findQualifyingTableName(String columnName, SqlNode ctx) Deprecated. -
findQualifyingTableNames
Map<String,org.apache.calcite.sql.validate.ScopeChild> findQualifyingTableNames(String columnName, SqlNode ctx, SqlNameMatcher nameMatcher) Finds all table aliases which are implicitly qualifying an unqualified column name.This method is only implemented in scopes (such as
SelectScope
) which can be the context for name-resolution. In scopes such asIdentifierNamespace
, it throwsUnsupportedOperationException
.- Parameters:
columnName
- Column namectx
- Validation context, to appear in any error thrownnameMatcher
- Name matcher- Returns:
- Map of applicable table alias and namespaces, never null, empty if no aliases found
-
findAllColumnNames
Collects theSqlMoniker
s of all possible columns in this scope.- Parameters:
result
- an array list of strings to add the result to
-
findAliases
Collects theSqlMoniker
s of all table aliases (uses of tables in query FROM clauses) available in this scope.- Parameters:
result
- a list of monikers to add the result to
-
fullyQualify
Converts an identifier into a fully-qualified identifier. For example, the "empno" in "select empno from emp natural join dept" becomes "emp.empno".- Returns:
- A qualified identifier, never null
-
isMeasureRef
Returns whether an expression is a reference to a measure column. -
addChild
Registers a relation in this scope.- Parameters:
ns
- Namespace representing the result-columns of the relationalias
- Alias with which to reference the relation, must not be nullnullable
- Whether this is a null-generating side of a join
-
lookupWindow
Finds a window with a given name. Returns null if not found. -
getMonotonicity
Returns whether an expression is monotonic in this scope. For example, if the scope has previously been sorted by columns X, Y, then X is monotonic in this scope, but Y is not. -
getOrderList
@Nullable SqlNodeList getOrderList()Returns the expressions by which the rows in this scope are sorted. If the rows are unsorted, returns null. -
resolveColumn
Resolves a single identifier to a column, and returns the datatype of that column.If it cannot find the column, returns null. If the column is ambiguous, throws an error with context
ctx
.- Parameters:
name
- Name of columnctx
- Context for exception- Returns:
- Type of column, if found and unambiguous; null if not found
-
getOperandScope
Returns the scope within which operands to a call are to be validated. Usually it is this scope, but when the call is to an aggregate function and this is an aggregating scope, it will be a a different scope.- Parameters:
call
- Call- Returns:
- Scope within which to validate arguments to call.
-
validateExpr
Performs any scope-specific validation of an expression. For example, an aggregating scope requires that expressions are valid aggregations. The expression has already been validated. -
getTableNamespace
Deprecated. -
resolveTable
void resolveTable(List<String> names, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved) Looks up a table in this scope from its name. If found, callsresolve(List, SqlNameMatcher, boolean, Resolved)
.TableNamespace
that wraps it. If the "table" is defined in aWITH
clause it may be a query, not a table after all.The name matcher is not null, and one typically uses
SqlValidatorCatalogReader.nameMatcher()
.- Parameters:
names
- Name of table, may be qualified or fully-qualifiednameMatcher
- Name matcherpath
- List of names that we have traversed through so far
-
nullifyType
Converts the type of an expression to nullable, if the context warrants it. -
isWithin
Returns whether this scope is enclosed withinscope2
in such a way that it can see the contents ofscope2
.
-
findQualifyingTableNames(String, SqlNode, SqlNameMatcher)