org.eigenbase.sql.validate
Class AbstractNamespace

java.lang.Object
  extended by org.eigenbase.sql.validate.AbstractNamespace
All Implemented Interfaces:
SqlValidatorNamespace
Direct Known Subclasses:
AliasNamespace, CollectNamespace, FieldNamespace, IdentifierNamespace, JoinNamespace, ParameterNamespace, ProcedureNamespace, SelectNamespace, SetopNamespace, TableConstructorNamespace, UnnestNamespace

abstract class AbstractNamespace
extends Object
implements SqlValidatorNamespace

Abstract implementation of SqlValidatorNamespace.

Since:
Mar 3, 2005
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/validate/AbstractNamespace.java#21 $
Author:
jhyde

Field Summary
protected  SqlNode enclosingNode
           
private  boolean forceNullable
           
protected  RelDataType rowType
          Type of the output row, which comprises the name and type of each output column.
private  SqlValidatorImpl.Status status
          Whether this scope is currently being validated.
protected  SqlValidatorImpl validator
           
 
Constructor Summary
AbstractNamespace(SqlValidatorImpl validator, SqlNode enclosingNode)
          Creates an AbstractNamespace.
 
Method Summary
 boolean fieldExists(String name)
          Returns whether this namespace has a field of a given name.
 SqlNode getEnclosingNode()
          Returns the parse tree node that at is at the root of this namespace and includes all decorations.
 List<Pair<SqlNode,SqlMonotonicity>> getMonotonicExprs()
          Returns a list of expressions which are monotonic in this namespace.
 SqlMonotonicity getMonotonicity(String columnName)
          Returns whether and how a given column is sorted.
 RelDataType getRowType()
          Returns the row type of this namespace, which comprises a list of names and types of the output columns.
 RelDataType getRowTypeSansSystemColumns()
          Returns the row type of this namespace, sans any system columns.
 SqlValidatorTable getTable()
          Returns the underlying table, or null if there is none.
 SqlValidator getValidator()
          Returns the validator.
 boolean isWrapperFor(Class<?> clazz)
          Returns whether this namespace implements a given interface, or wraps a class which does.
 SqlValidatorNamespace lookupChild(String name)
          Looks up a child namespace of a given name.
 void makeNullable()
          Makes all fields in this namespace nullable (typically because it is on the outer side of an outer join.
 void setRowType(RelDataType rowType)
          Allows RowType for the namespace to be explicitly set.
 String translate(String name)
          Translates a field name to the name in the underlying namespace.
<T> T
unwrap(Class<T> clazz)
          Returns this namespace, or a wrapped namespace, cast to a particular class.
 void validate()
          Validates this namespace.
protected abstract  RelDataType validateImpl()
          Validates this scope and returns the type of the records it returns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.sql.validate.SqlValidatorNamespace
getNode
 

Field Detail

validator

protected final SqlValidatorImpl validator

status

private SqlValidatorImpl.Status status
Whether this scope is currently being validated. Used to check for cycles.


rowType

protected RelDataType rowType
Type of the output row, which comprises the name and type of each output column. Set on validate.


forceNullable

private boolean forceNullable

enclosingNode

protected final SqlNode enclosingNode
Constructor Detail

AbstractNamespace

AbstractNamespace(SqlValidatorImpl validator,
                  SqlNode enclosingNode)
Creates an AbstractNamespace.

Parameters:
validator - Validator
enclosingNode - Enclosing node
Method Detail

getValidator

public SqlValidator getValidator()
Description copied from interface: SqlValidatorNamespace
Returns the validator.

Specified by:
getValidator in interface SqlValidatorNamespace
Returns:
validator

validate

public final void validate()
Description copied from interface: SqlValidatorNamespace
Validates this namespace.

If the scope has already been validated, does nothing.

Please call SqlValidatorImpl.validateNamespace(org.eigenbase.sql.validate.SqlValidatorNamespace) rather than calling this method directly.

Specified by:
validate in interface SqlValidatorNamespace

validateImpl

protected abstract RelDataType validateImpl()
Validates this scope and returns the type of the records it returns. External users should call validate(), which uses the status field to protect against cycles.

Returns:
record data type, never null
"Postcondition:"
return != null

getRowType

public RelDataType getRowType()
Description copied from interface: SqlValidatorNamespace
Returns the row type of this namespace, which comprises a list of names and types of the output columns. If the scope's type has not yet been derived, derives it. Never returns null.

Specified by:
getRowType in interface SqlValidatorNamespace

getRowTypeSansSystemColumns

public RelDataType getRowTypeSansSystemColumns()
Description copied from interface: SqlValidatorNamespace
Returns the row type of this namespace, sans any system columns.

Specified by:
getRowTypeSansSystemColumns in interface SqlValidatorNamespace
Returns:
Row type sans system columns

setRowType

public void setRowType(RelDataType rowType)
Description copied from interface: SqlValidatorNamespace
Allows RowType for the namespace to be explicitly set.

Specified by:
setRowType in interface SqlValidatorNamespace

getEnclosingNode

public SqlNode getEnclosingNode()
Description copied from interface: SqlValidatorNamespace
Returns the parse tree node that at is at the root of this namespace and includes all decorations. If there are no decorations, returns the same as SqlValidatorNamespace.getNode().

Specified by:
getEnclosingNode in interface SqlValidatorNamespace

getTable

public SqlValidatorTable getTable()
Description copied from interface: SqlValidatorNamespace
Returns the underlying table, or null if there is none.

Specified by:
getTable in interface SqlValidatorNamespace

lookupChild

public SqlValidatorNamespace lookupChild(String name)
Description copied from interface: SqlValidatorNamespace
Looks up a child namespace of a given name.

For example, in the query select e.name from emps as e, e is an IdentifierNamespace which has a child name which is a FieldNamespace.

Specified by:
lookupChild in interface SqlValidatorNamespace
Parameters:
name - Name of namespace
Returns:
Namespace

fieldExists

public boolean fieldExists(String name)
Description copied from interface: SqlValidatorNamespace
Returns whether this namespace has a field of a given name.

Specified by:
fieldExists in interface SqlValidatorNamespace
Parameters:
name - Field name
Returns:
Whether field exists

getMonotonicExprs

public List<Pair<SqlNode,SqlMonotonicity>> getMonotonicExprs()
Description copied from interface: SqlValidatorNamespace
Returns a list of expressions which are monotonic in this namespace. For example, if the namespace represents a relation ordered by a column called "TIMESTAMP", then the list would contain a SqlIdentifier called "TIMESTAMP".

Specified by:
getMonotonicExprs in interface SqlValidatorNamespace

getMonotonicity

public SqlMonotonicity getMonotonicity(String columnName)
Description copied from interface: SqlValidatorNamespace
Returns whether and how a given column is sorted.

Specified by:
getMonotonicity in interface SqlValidatorNamespace

makeNullable

public void makeNullable()
Description copied from interface: SqlValidatorNamespace
Makes all fields in this namespace nullable (typically because it is on the outer side of an outer join.

Specified by:
makeNullable in interface SqlValidatorNamespace

translate

public String translate(String name)
Description copied from interface: SqlValidatorNamespace
Translates a field name to the name in the underlying namespace.

Specified by:
translate in interface SqlValidatorNamespace

unwrap

public <T> T unwrap(Class<T> clazz)
Description copied from interface: SqlValidatorNamespace
Returns this namespace, or a wrapped namespace, cast to a particular class.

Specified by:
unwrap in interface SqlValidatorNamespace
Parameters:
clazz - Desired type
Returns:
This namespace cast to desired type

isWrapperFor

public boolean isWrapperFor(Class<?> clazz)
Description copied from interface: SqlValidatorNamespace
Returns whether this namespace implements a given interface, or wraps a class which does.

Specified by:
isWrapperFor in interface SqlValidatorNamespace
Parameters:
clazz - Interface
Returns:
Whether namespace implements given interface