org.eigenbase.sql
Class SqlIdentifier

java.lang.Object
  extended by org.eigenbase.sql.SqlNode
      extended by org.eigenbase.sql.SqlIdentifier
All Implemented Interfaces:
Cloneable

public class SqlIdentifier
extends SqlNode

A SqlIdentifier is an identifier, possibly compound.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/SqlIdentifier.java#34 $
Author:
jhyde

Field Summary
(package private)  SqlCollation collation
          This identifier's collation (if any).
private  SqlParserPos[] componentPositions
          A list of the positions of the components of compound identifiers.
 String[] names
          Array of the components of this compound identifier.
 
Fields inherited from class org.eigenbase.sql.SqlNode
emptyArray
 
Constructor Summary
SqlIdentifier(String[] names, SqlCollation collation, SqlParserPos pos, SqlParserPos[] componentPositions)
          Creates a compound identifier, for example foo.bar.
SqlIdentifier(String[] names, SqlParserPos pos)
           
SqlIdentifier(String name, SqlCollation collation, SqlParserPos pos)
          Creates a simple identifier, for example foo, with a collation.
SqlIdentifier(String name, SqlParserPos pos)
          Creates a simple identifier, for example foo.
 
Method Summary
<R> R
accept(SqlVisitor<R> visitor)
          Accepts a generic visitor.
 void assignNamesFrom(SqlIdentifier other)
          Copies names and components from another identifier.
 SqlNode clone(SqlParserPos pos)
          Clones a SqlNode with a different position.
 boolean equalsBaseName(String name)
           
 boolean equalsDeep(SqlNode node, boolean fail)
          Returns whether this node is structurally equivalent to another node.
 SqlCollation getCollation()
           
 SqlIdentifier getComponent(int ordinal)
          Creates an identifier which contains only the ordinalth component of this compound identifier.
 SqlParserPos getComponentParserPosition(int i)
          Returns the position of the ith component of a compound identifier, or the position of the whole identifier if that information is not present.
 SqlKind getKind()
          Returns the type of node this is, or SqlKind.Other if it's nothing special.
 SqlMonotonicity getMonotonicity(SqlValidatorScope scope)
          Returns whether expression is always ascending, descending or constant.
 String getSimple()
           
 boolean isSimple()
          Returns whether this is a simple identifier.
 boolean isStar()
          Returns whether this identifier is a star, such as "*" or "foo.bar.*".
 void setNames(String[] names, SqlParserPos[] poses)
          Deprecated. Identifiers should be immutable
 String toString()
           
 void unparse(SqlWriter writer, int leftPrec, int rightPrec)
          Writes a SQL representation of this node to a writer.
 void validate(SqlValidator validator, SqlValidatorScope scope)
          Validates this node.
 void validateExpr(SqlValidator validator, SqlValidatorScope scope)
          Validates this node in an expression context.
 
Methods inherited from class org.eigenbase.sql.SqlNode
clone, cloneArray, equalDeep, findValidOptions, getParserPosition, isA, toSqlString, toSqlString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

names

public String[] names
Array of the components of this compound identifier.

It's convenient to have this member public, and it's convenient to have this member not-final, but it's a shame it's public and not-final. If you assign to this member, please use setNames(String[], SqlParserPos[]). And yes, we'd like to make identifiers immutable one day.


collation

SqlCollation collation
This identifier's collation (if any).


componentPositions

private SqlParserPos[] componentPositions
A list of the positions of the components of compound identifiers.

Constructor Detail

SqlIdentifier

public SqlIdentifier(String[] names,
                     SqlCollation collation,
                     SqlParserPos pos,
                     SqlParserPos[] componentPositions)
Creates a compound identifier, for example foo.bar.

Parameters:
names - Parts of the identifier, length >= 1

SqlIdentifier

public SqlIdentifier(String[] names,
                     SqlParserPos pos)

SqlIdentifier

public SqlIdentifier(String name,
                     SqlCollation collation,
                     SqlParserPos pos)
Creates a simple identifier, for example foo, with a collation.


SqlIdentifier

public SqlIdentifier(String name,
                     SqlParserPos pos)
Creates a simple identifier, for example foo.

Method Detail

getKind

public SqlKind getKind()
Description copied from class: SqlNode
Returns the type of node this is, or SqlKind.Other if it's nothing special.

Overrides:
getKind in class SqlNode
Returns:
a SqlKind value, never null

clone

public SqlNode clone(SqlParserPos pos)
Description copied from class: SqlNode
Clones a SqlNode with a different position.

Overrides:
clone in class SqlNode

toString

public String toString()
Overrides:
toString in class SqlNode

setNames

public void setNames(String[] names,
                     SqlParserPos[] poses)
Deprecated. Identifiers should be immutable

Modifies the components of this identifier and their positions.

Parameters:
names - Names of components
poses - Positions of components

getComponentParserPosition

public SqlParserPos getComponentParserPosition(int i)
Returns the position of the ith component of a compound identifier, or the position of the whole identifier if that information is not present.

Parameters:
i - Ordinal of component.
Returns:
Position of i'th component

assignNamesFrom

public void assignNamesFrom(SqlIdentifier other)
Copies names and components from another identifier. Does not modify the cross-component parser position.

Parameters:
other - identifer from which to copy

getComponent

public SqlIdentifier getComponent(int ordinal)
Creates an identifier which contains only the ordinalth component of this compound identifier. It will have the correct SqlParserPos, provided that detailed position information is available.


unparse

public void unparse(SqlWriter writer,
                    int leftPrec,
                    int rightPrec)
Description copied from class: SqlNode
Writes a SQL representation of this node to a writer.

The leftPrec and rightPrec parameters give us enough context to decide whether we need to enclose the expression in parentheses. For example, we need parentheses around "2 + 3" if preceded by "5 *". This is because the precedence of the "*" operator is greater than the precedence of the "+" operator.

The algorithm handles left- and right-associative operators by giving them slightly different left- and right-precedence.

If SqlWriter.isAlwaysUseParentheses() is true, we use parentheses even when they are not required by the precedence rules.

For the details of this algorithm, see SqlCall.unparse(org.eigenbase.sql.SqlWriter, int, int).

Specified by:
unparse in class SqlNode
Parameters:
writer - Target writer
leftPrec - The precedence of the SqlNode immediately preceding this node in a depth-first scan of the parse tree
rightPrec - The precedence of the SqlNode immediately

validate

public void validate(SqlValidator validator,
                     SqlValidatorScope scope)
Description copied from class: SqlNode
Validates this node.

The typical implementation of this method will make a callback to the validator appropriate to the node type and context. The validator has methods such as SqlValidator.validateLiteral(org.eigenbase.sql.SqlLiteral) for these purposes.

Specified by:
validate in class SqlNode
scope - Validator

validateExpr

public void validateExpr(SqlValidator validator,
                         SqlValidatorScope scope)
Description copied from class: SqlNode
Validates this node in an expression context.

Usually, this method does much the same as SqlNode.validate(org.eigenbase.sql.validate.SqlValidator, org.eigenbase.sql.validate.SqlValidatorScope), but a SqlIdentifier can occur in expression and non-expression contexts.

Overrides:
validateExpr in class SqlNode

equalsDeep

public boolean equalsDeep(SqlNode node,
                          boolean fail)
Description copied from class: SqlNode
Returns whether this node is structurally equivalent to another node. Some examples:

Specified by:
equalsDeep in class SqlNode

accept

public <R> R accept(SqlVisitor<R> visitor)
Description copied from class: SqlNode
Accepts a generic visitor.

Implementations of this method in subtypes simply call the appropriate visit method on the visitor object.

The type parameter R must be consistent with the type parameter of the visitor.

Specified by:
accept in class SqlNode

getCollation

public SqlCollation getCollation()

getSimple

public String getSimple()

isStar

public boolean isStar()
Returns whether this identifier is a star, such as "*" or "foo.bar.*".


isSimple

public boolean isSimple()
Returns whether this is a simple identifier. "FOO" is simple; "*", "FOO.*" and "FOO.BAR" are not.


getMonotonicity

public SqlMonotonicity getMonotonicity(SqlValidatorScope scope)
Description copied from class: SqlNode
Returns whether expression is always ascending, descending or constant. This property is useful because it allows to safely aggregte infinite streams of values.

The default implementation returns SqlMonotonicity.NotMonotonic.

Overrides:
getMonotonicity in class SqlNode

equalsBaseName

public boolean equalsBaseName(String name)