org.eigenbase.sql.validate
Class EmptyScope

java.lang.Object
  extended by org.eigenbase.sql.validate.EmptyScope
All Implemented Interfaces:
SqlValidatorScope
Direct Known Subclasses:
ParameterScope

 class EmptyScope
extends Object
implements SqlValidatorScope

Deviant implementation of SqlValidatorScope 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.)

Since:
Mar 25, 2003
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/validate/EmptyScope.java#13 $
Author:
jhyde

Field Summary
protected  SqlValidatorImpl validator
           
 
Constructor Summary
EmptyScope(SqlValidatorImpl validator)
           
 
Method Summary
 void addChild(SqlValidatorNamespace ns, String alias)
          Registers a relation in this scope.
 void findAliases(List<SqlMoniker> result)
          Collects the SqlMonikers of all table aliases (uses of tables in query FROM clauses) available in this scope.
 void findAllColumnNames(List<SqlMoniker> result)
          Collects the SqlMonikers of all possible columns in this scope.
 void findAllTableNames(List<SqlMoniker> result)
           
 String findQualifyingTableName(String columnName, SqlNode ctx)
          Finds the table alias which is implicitly qualifying an unqualified column name.
 SqlIdentifier 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.
 SqlValidator getValidator()
          Returns the validator which created this scope.
 SqlWindow lookupWindow(String name)
          Finds a window with a given name.
 SqlValidatorNamespace resolve(String name, SqlValidatorScope[] ancestorOut, int[] offsetOut)
          Looks up a node with a given name.
 RelDataType resolveColumn(String name, SqlNode ctx)
          Resolves a single identifier to a column, and returns the datatype of that column.
 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
 

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 interface SqlValidatorScope

fullyQualify

public SqlIdentifier 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 interface SqlValidatorScope

getNode

public SqlNode getNode()
Description copied from interface: SqlValidatorScope
Returns the root node of this scope.

Specified by:
getNode in interface SqlValidatorScope

resolve

public SqlValidatorNamespace resolve(String name,
                                     SqlValidatorScope[] ancestorOut,
                                     int[] offsetOut)
Description copied from interface: SqlValidatorScope
Looks up a node with a given name. Returns null if none is found.

Specified by:
resolve in interface SqlValidatorScope
Parameters:
name - Name of node to find
ancestorOut - If not null, writes the ancestor scope here
offsetOut - If not null, writes the offset within the ancestor here

findAllColumnNames

public void findAllColumnNames(List<SqlMoniker> result)
Description copied from interface: SqlValidatorScope
Collects the SqlMonikers of all possible columns in this scope.

Specified by:
findAllColumnNames in interface SqlValidatorScope
Parameters:
result - an array list of strings to add the result to

findAllTableNames

public void findAllTableNames(List<SqlMoniker> result)

findAliases

public void findAliases(List<SqlMoniker> result)
Description copied from interface: SqlValidatorScope
Collects the SqlMonikers of all table aliases (uses of tables in query FROM clauses) available in this scope.

Specified by:
findAliases in interface SqlValidatorScope
Parameters:
result - a list of monikers to add the result to

resolveColumn

public RelDataType resolveColumn(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 interface SqlValidatorScope
Parameters:
name - Name of column
ctx - 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 interface SqlValidatorScope
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 interface SqlValidatorScope

findQualifyingTableName

public String findQualifyingTableName(String columnName,
                                      SqlNode ctx)
Description copied from interface: SqlValidatorScope
Finds the table alias which is implicitly qualifying an unqualified column name. Throws an error if there is not exactly one table.

This method is only implemented in scopes (such as SelectScope) which can be the context for name-resolution. In scopes such as IdentifierNamespace, it throws UnsupportedOperationException.

Specified by:
findQualifyingTableName in interface SqlValidatorScope
Parameters:
columnName - Column name
ctx - Validation context, to appear in any error thrown
Returns:
Table alias

addChild

public void addChild(SqlValidatorNamespace ns,
                     String alias)
Description copied from interface: SqlValidatorScope
Registers a relation in this scope.

Specified by:
addChild in interface SqlValidatorScope
Parameters:
ns - Namespace representing the result-columns of the relation
alias - Alias with which to reference the relation, must not be null

lookupWindow

public SqlWindow lookupWindow(String name)
Description copied from interface: SqlValidatorScope
Finds a window with a given name. Returns null if not found.

Specified by:
lookupWindow in interface SqlValidatorScope

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 interface SqlValidatorScope

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 interface SqlValidatorScope