Class DelegatingScope
- All Implemented Interfaces:
SqlValidatorScope
- Direct Known Subclasses:
AggregatingSelectScope,GroupByScope,ListScope,MeasureScope,OrderByScope
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.calcite.sql.validate.SqlValidatorScope
SqlValidatorScope.EmptyPath, SqlValidatorScope.Path, SqlValidatorScope.Resolve, SqlValidatorScope.Resolved, SqlValidatorScope.ResolvedImpl, SqlValidatorScope.Step -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SqlValidatorScopeParent scope.Computes and stores information that cannot be computed on construction, but only after sub-queries have been validated.protected final SqlValidatorImpl -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(SqlValidatorNamespace ns, String alias, boolean nullable) Registers a relation in this scope.protected voidaddColumnNames(SqlValidatorNamespace ns, List<SqlMoniker> colNames) protected voidanalyze(org.apache.calcite.sql.validate.SqlValidatorUtil.GroupAnalyzer analyzer) Analyzes expressions in this scope and populates aGroupAnalyzer.voidfindAliases(Collection<SqlMoniker> result) Collects theSqlMonikers of all table aliases (uses of tables in query FROM clauses) available in this scope.voidfindAllColumnNames(List<SqlMoniker> result) Collects theSqlMonikers of all possible columns in this scope.findQualifyingTableName(String columnName, SqlNode ctx) 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.getOperandScope(SqlCall call) Returns the scope within which operands to a call are to be validated.@Nullable SqlNodeListReturns the expressions by which the rows in this scope are sorted.Returns the parent scope of thisDelegatingScope.@Nullable SqlValidatorNamespacegetTableNamespace(List<String> names) Returns the validator which created this scope.@Nullable SqlWindowlookupWindow(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.protected @Nullable SqlQualifiedqualifyUsingAlias(SqlSelect select, SqlIdentifier identifier) Qualifies an identifier by looking for an alias in the current select-list.voidresolve(List<String> names, SqlNameMatcher nameMatcher, boolean deep, SqlValidatorScope.Resolved resolved) Looks up a node with a given name.@Nullable RelDataTyperesolveColumn(String name, SqlNode ctx) Resolves a single identifier to a column, and returns the datatype of that column.voidresolveTable(List<String> names, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved) Looks up a table in this scope from its name.voidvalidateExpr(SqlNode expr) Performs any scope-specific validation of an expression.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.calcite.sql.validate.SqlValidatorScope
getNode, isMeasureRef, isWithin
-
Field Details
-
parent
Parent scope. This is where to look next to resolve an identifier; it is not always the parent object in the parse tree.This is never null: at the top of the tree, it is an
EmptyScope. -
validator
-
resolved
Computes and stores information that cannot be computed on construction, but only after sub-queries have been validated.
-
-
Method Details
-
addChild
Description copied from interface:SqlValidatorScopeRegisters a relation in this scope.- Specified by:
addChildin interfaceSqlValidatorScope- 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
-
resolve
public void resolve(List<String> names, SqlNameMatcher nameMatcher, boolean deep, SqlValidatorScope.Resolved resolved) Description copied from interface:SqlValidatorScopeLooks up a node with a given name. Adds the match(es) to the resolved if found.- Specified by:
resolvein interfaceSqlValidatorScope- 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
-
addColumnNames
-
findAllColumnNames
Description copied from interface:SqlValidatorScopeCollects theSqlMonikers of all possible columns in this scope.- Specified by:
findAllColumnNamesin interfaceSqlValidatorScope- Parameters:
result- an array list of strings to add the result to
-
findAliases
Description copied from interface:SqlValidatorScopeCollects theSqlMonikers of all table aliases (uses of tables in query FROM clauses) available in this scope.- Specified by:
findAliasesin interfaceSqlValidatorScope- Parameters:
result- a list of monikers to add the result to
-
findQualifyingTableName
- Specified by:
findQualifyingTableNamein interfaceSqlValidatorScope
-
findQualifyingTableNames
public Map<String,org.apache.calcite.sql.validate.ScopeChild> findQualifyingTableNames(String columnName, SqlNode ctx, SqlNameMatcher nameMatcher) Description copied from interface:SqlValidatorScopeFinds 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.- Specified by:
findQualifyingTableNamesin interfaceSqlValidatorScope- 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
-
resolveColumn
Description copied from interface:SqlValidatorScopeResolves 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.- Specified by:
resolveColumnin interfaceSqlValidatorScope- Parameters:
name- Name of columnctx- Context for exception- Returns:
- Type of column, if found and unambiguous; null if not found
-
nullifyType
Description copied from interface:SqlValidatorScopeConverts the type of an expression to nullable, if the context warrants it.- Specified by:
nullifyTypein interfaceSqlValidatorScope
-
getTableNamespace
- Specified by:
getTableNamespacein interfaceSqlValidatorScope
-
resolveTable
public void resolveTable(List<String> names, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved) Description copied from interface:SqlValidatorScopeLooks up a table in this scope from its name. If found, callsSqlValidatorScope.resolve(List, SqlNameMatcher, boolean, Resolved).TableNamespacethat wraps it. If the "table" is defined in aWITHclause it may be a query, not a table after all.The name matcher is not null, and one typically uses
SqlValidatorCatalogReader.nameMatcher().- Specified by:
resolveTablein interfaceSqlValidatorScope- Parameters:
names- Name of table, may be qualified or fully-qualifiednameMatcher- Name matcherpath- List of names that we have traversed through so far
-
getOperandScope
Description copied from interface:SqlValidatorScopeReturns 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.- Specified by:
getOperandScopein interfaceSqlValidatorScope- Parameters:
call- Call- Returns:
- Scope within which to validate arguments to call.
-
getValidator
Description copied from interface:SqlValidatorScopeReturns the validator which created this scope.- Specified by:
getValidatorin interfaceSqlValidatorScope
-
fullyQualify
Converts an identifier into a fully-qualified identifier. For example, the "empno" in "select empno from emp natural join dept" becomes "emp.empno".If the identifier cannot be resolved, throws. Never returns null.
- Specified by:
fullyQualifyin interfaceSqlValidatorScope- Returns:
- A qualified identifier, never null
-
validateExpr
Description copied from interface:SqlValidatorScopePerforms any scope-specific validation of an expression. For example, an aggregating scope requires that expressions are valid aggregations. The expression has already been validated.- Specified by:
validateExprin interfaceSqlValidatorScope
-
lookupWindow
Description copied from interface:SqlValidatorScopeFinds a window with a given name. Returns null if not found.- Specified by:
lookupWindowin interfaceSqlValidatorScope
-
getMonotonicity
Description copied from interface:SqlValidatorScopeReturns 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.- Specified by:
getMonotonicityin interfaceSqlValidatorScope
-
getOrderList
Description copied from interface:SqlValidatorScopeReturns the expressions by which the rows in this scope are sorted. If the rows are unsorted, returns null.- Specified by:
getOrderListin interfaceSqlValidatorScope
-
analyze
protected void analyze(org.apache.calcite.sql.validate.SqlValidatorUtil.GroupAnalyzer analyzer) Analyzes expressions in this scope and populates aGroupAnalyzer. -
getParent
Returns the parent scope of thisDelegatingScope. -
qualifyUsingAlias
Qualifies an identifier by looking for an alias in the current select-list.Used when resolving ORDER BY items (when the conformance allows order by alias, such as "SELECT x - y AS z FROM t ORDER BY z") and measures (when one measure refers to another, for example "SELECT SUM(x) AS MEASURE m1, SUM(y) - m1 AS MEASURE m2 FROM t").
-