Package org.apache.calcite.sql.validate
Class EmptyScope
- java.lang.Object
-
- org.apache.calcite.sql.validate.EmptyScope
-
- All Implemented Interfaces:
SqlValidatorScope
- Direct Known Subclasses:
ParameterScope
class EmptyScope extends java.lang.Object implements SqlValidatorScope
Deviant implementation ofSqlValidatorScope
for the top of the scope stack.It is convenient, because we never need to check whether a scope's parent is null. (This scope knows not to ask about its parents, just like Adam.)
-
-
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
Fields Modifier and Type Field Description protected SqlValidatorImpl
validator
-
Constructor Summary
Constructors Constructor Description EmptyScope(SqlValidatorImpl validator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(SqlValidatorNamespace ns, java.lang.String alias, boolean nullable)
Registers a relation in this scope.void
findAliases(java.util.Collection<SqlMoniker> result)
Collects theSqlMoniker
s of all table aliases (uses of tables in query FROM clauses) available in this scope.void
findAllColumnNames(java.util.List<SqlMoniker> result)
Collects theSqlMoniker
s of all possible columns in this scope.void
findAllTableNames(java.util.List<SqlMoniker> result)
Pair<java.lang.String,SqlValidatorNamespace>
findQualifyingTableName(java.lang.String columnName, SqlNode ctx)
java.util.Map<java.lang.String,ScopeChild>
findQualifyingTableNames(java.lang.String columnName, SqlNode ctx, SqlNameMatcher nameMatcher)
Finds all table aliases which are implicitly qualifying an unqualified column name.SqlQualified
fullyQualify(SqlIdentifier identifier)
Converts an identifier into a fully-qualified identifier.SqlMonotonicity
getMonotonicity(SqlNode expr)
Returns whether an expression is monotonic in this scope.SqlNode
getNode()
Returns the root node of this scope.SqlValidatorScope
getOperandScope(SqlCall call)
Returns the scope within which operands to a call are to be validated.SqlNodeList
getOrderList()
Returns the expressions by which the rows in this scope are sorted.SqlValidatorNamespace
getTableNamespace(java.util.List<java.lang.String> names)
SqlValidator
getValidator()
Returns the validator which created this scope.SqlWindow
lookupWindow(java.lang.String name)
Finds a window with a given name.RelDataType
nullifyType(SqlNode node, RelDataType type)
Converts the type of an expression to nullable, if the context warrants it.void
resolve(java.util.List<java.lang.String> names, SqlNameMatcher nameMatcher, boolean deep, SqlValidatorScope.Resolved resolved)
Looks up a node with a given name.private void
resolve_(CalciteSchema rootSchema, java.util.List<java.lang.String> names, java.util.List<java.lang.String> schemaNames, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved)
RelDataType
resolveColumn(java.lang.String name, SqlNode ctx)
Resolves a single identifier to a column, and returns the datatype of that column.void
resolveTable(java.util.List<java.lang.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.calcite.sql.validate.SqlValidatorScope
isWithin
-
-
-
-
Field Detail
-
validator
protected final SqlValidatorImpl validator
-
-
Constructor Detail
-
EmptyScope
EmptyScope(SqlValidatorImpl validator)
-
-
Method Detail
-
getValidator
public SqlValidator getValidator()
Description copied from interface:SqlValidatorScope
Returns the validator which created this scope.- Specified by:
getValidator
in interfaceSqlValidatorScope
-
fullyQualify
public SqlQualified fullyQualify(SqlIdentifier identifier)
Description copied from interface:SqlValidatorScope
Converts an identifier into a fully-qualified identifier. For example, the "empno" in "select empno from emp natural join dept" becomes "emp.empno".- Specified by:
fullyQualify
in interfaceSqlValidatorScope
- Returns:
- A qualified identifier, never null
-
getNode
public SqlNode getNode()
Description copied from interface:SqlValidatorScope
Returns the root node of this scope. Never null.- Specified by:
getNode
in interfaceSqlValidatorScope
-
resolve
public void resolve(java.util.List<java.lang.String> names, SqlNameMatcher nameMatcher, boolean deep, SqlValidatorScope.Resolved resolved)
Description copied from interface:SqlValidatorScope
Looks up a node with a given name. Returns null if none is found.- Specified by:
resolve
in 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
-
getTableNamespace
public SqlValidatorNamespace getTableNamespace(java.util.List<java.lang.String> names)
- Specified by:
getTableNamespace
in interfaceSqlValidatorScope
-
resolveTable
public void resolveTable(java.util.List<java.lang.String> names, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved)
Description copied from interface:SqlValidatorScope
Looks up a table in this scope from its name. If found, callsSqlValidatorScope.resolve(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()
.- Specified by:
resolveTable
in interfaceSqlValidatorScope
- Parameters:
names
- Name of table, may be qualified or fully-qualifiednameMatcher
- Name matcherpath
- List of names that we have traversed through so far
-
resolve_
private void resolve_(CalciteSchema rootSchema, java.util.List<java.lang.String> names, java.util.List<java.lang.String> schemaNames, SqlNameMatcher nameMatcher, SqlValidatorScope.Path path, SqlValidatorScope.Resolved resolved)
-
nullifyType
public RelDataType nullifyType(SqlNode node, RelDataType type)
Description copied from interface:SqlValidatorScope
Converts the type of an expression to nullable, if the context warrants it.- Specified by:
nullifyType
in interfaceSqlValidatorScope
-
findAllColumnNames
public void findAllColumnNames(java.util.List<SqlMoniker> result)
Description copied from interface:SqlValidatorScope
Collects theSqlMoniker
s of all possible columns in this scope.- Specified by:
findAllColumnNames
in interfaceSqlValidatorScope
- Parameters:
result
- an array list of strings to add the result to
-
findAllTableNames
public void findAllTableNames(java.util.List<SqlMoniker> result)
-
findAliases
public void findAliases(java.util.Collection<SqlMoniker> result)
Description copied from interface:SqlValidatorScope
Collects theSqlMoniker
s of all table aliases (uses of tables in query FROM clauses) available in this scope.- Specified by:
findAliases
in interfaceSqlValidatorScope
- Parameters:
result
- a list of monikers to add the result to
-
resolveColumn
public RelDataType resolveColumn(java.lang.String name, SqlNode ctx)
Description copied from interface:SqlValidatorScope
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
.- Specified by:
resolveColumn
in interfaceSqlValidatorScope
- Parameters:
name
- Name of columnctx
- Context for exception- Returns:
- Type of column, if found and unambiguous; null if not found
-
getOperandScope
public SqlValidatorScope getOperandScope(SqlCall call)
Description copied from interface:SqlValidatorScope
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.- Specified by:
getOperandScope
in interfaceSqlValidatorScope
- Parameters:
call
- Call- Returns:
- Scope within which to validate arguments to call.
-
validateExpr
public void validateExpr(SqlNode expr)
Description copied from interface:SqlValidatorScope
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.- Specified by:
validateExpr
in interfaceSqlValidatorScope
-
findQualifyingTableName
public Pair<java.lang.String,SqlValidatorNamespace> findQualifyingTableName(java.lang.String columnName, SqlNode ctx)
- Specified by:
findQualifyingTableName
in interfaceSqlValidatorScope
-
findQualifyingTableNames
public java.util.Map<java.lang.String,ScopeChild> findQualifyingTableNames(java.lang.String columnName, SqlNode ctx, SqlNameMatcher nameMatcher)
Description copied from interface:SqlValidatorScope
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
.- Specified by:
findQualifyingTableNames
in 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
-
addChild
public void addChild(SqlValidatorNamespace ns, java.lang.String alias, boolean nullable)
Description copied from interface:SqlValidatorScope
Registers a relation in this scope.- Specified by:
addChild
in 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
-
lookupWindow
public SqlWindow lookupWindow(java.lang.String name)
Description copied from interface:SqlValidatorScope
Finds a window with a given name. Returns null if not found.- Specified by:
lookupWindow
in interfaceSqlValidatorScope
-
getMonotonicity
public SqlMonotonicity getMonotonicity(SqlNode expr)
Description copied from interface:SqlValidatorScope
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.- Specified by:
getMonotonicity
in interfaceSqlValidatorScope
-
getOrderList
public SqlNodeList getOrderList()
Description copied from interface:SqlValidatorScope
Returns the expressions by which the rows in this scope are sorted. If the rows are unsorted, returns null.- Specified by:
getOrderList
in interfaceSqlValidatorScope
-
-