org.eigenbase.sql
Class SqlCall

java.lang.Object
  extended by org.eigenbase.sql.SqlNode
      extended by org.eigenbase.sql.SqlCall
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
SqlCase, SqlDelete, SqlExplain, SqlInsert, SqlJoin, SqlMerge, SqlSelect, SqlUpdate, SqlWindow

public class SqlCall
extends SqlNode

A SqlCall is a call to an operator. (Operators can be used to describe any syntactic construct, so in practice, every non-leaf node in a SQL parse tree is a SqlCall of some kind.)


Field Summary
private  boolean expanded
           
private  SqlLiteral functionQuantifier
           
 SqlNode[] operands
           
private  SqlOperator operator
           
 
Fields inherited from class org.eigenbase.sql.SqlNode
emptyArray
 
Constructor Summary
  SqlCall(SqlOperator operator, SqlNode[] operands, SqlParserPos pos)
           
protected SqlCall(SqlOperator operator, SqlNode[] operands, SqlParserPos pos, boolean expanded, SqlLiteral functionQualifier)
           
 
Method Summary
<R> R
accept(SqlVisitor<R> visitor)
          Accepts a generic visitor.
 SqlNode clone(SqlParserPos pos)
          Clones a SqlNode with a different position.
 boolean equalsDeep(SqlNode node, boolean fail)
          Returns whether this node is structurally equivalent to another node.
 void findValidOptions(SqlValidator validator, SqlValidatorScope scope, SqlParserPos pos, List<SqlMoniker> hintList)
          Lists all the valid alternatives for this node if the parse position of the node matches that of pos.
protected  String getCallSignature(SqlValidator validator, SqlValidatorScope scope)
          Returns a string describing the actual argument types of a call, e.g.
 SqlLiteral getFunctionQuantifier()
           
 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.
 SqlNode[] getOperands()
           
 SqlOperator getOperator()
           
 boolean isA(SqlKind kind)
          Returns whether this node is a particular kind.
 boolean isCountStar()
          Test to see if it is the function COUNT(*)
 boolean isExpanded()
          Whether this call was created by expanding a parentheses-free call to what was syntactically an identifier.
 boolean isName(String name)
          Tests whether operator name matches supplied value.
 void setOperand(int i, SqlNode operand)
           
 void setOperator(SqlOperator operator)
           
 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 call.
 
Methods inherited from class org.eigenbase.sql.SqlNode
clone, cloneArray, equalDeep, getParserPosition, toSqlString, toSqlString, toString, validateExpr
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

operator

private SqlOperator operator

operands

public final SqlNode[] operands

functionQuantifier

private final SqlLiteral functionQuantifier

expanded

private final boolean expanded
Constructor Detail

SqlCall

public SqlCall(SqlOperator operator,
               SqlNode[] operands,
               SqlParserPos pos)

SqlCall

protected SqlCall(SqlOperator operator,
                  SqlNode[] operands,
                  SqlParserPos pos,
                  boolean expanded,
                  SqlLiteral functionQualifier)
Method Detail

isA

public boolean isA(SqlKind kind)
Description copied from class: SqlNode
Returns whether this node is a particular kind.

Overrides:
isA in class SqlNode
Parameters:
kind - a SqlKind value

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

isExpanded

public boolean isExpanded()
Whether this call was created by expanding a parentheses-free call to what was syntactically an identifier.


setOperand

public void setOperand(int i,
                       SqlNode operand)

setOperator

public void setOperator(SqlOperator operator)

getOperator

public SqlOperator getOperator()

getOperands

public SqlNode[] getOperands()

clone

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

Overrides:
clone in class SqlNode

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 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)
Validates this call.

The default implementation delegates the validation to the operator's SqlOperator.validateCall(org.eigenbase.sql.SqlCall, org.eigenbase.sql.validate.SqlValidator, org.eigenbase.sql.validate.SqlValidatorScope, org.eigenbase.sql.validate.SqlValidatorScope). Derived classes may override (as do, for example SqlSelect and SqlUpdate).

Specified by:
validate in class SqlNode
scope - Validator

findValidOptions

public void findValidOptions(SqlValidator validator,
                             SqlValidatorScope scope,
                             SqlParserPos pos,
                             List<SqlMoniker> hintList)
Description copied from class: SqlNode
Lists all the valid alternatives for this node if the parse position of the node matches that of pos. Only implemented now for SqlCall and SqlOperator.

Overrides:
findValidOptions in class SqlNode
Parameters:
validator - Validator
scope - Validation scope
pos - SqlParserPos indicating the cursor position at which competion hints are requested for
hintList - list of valid options

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

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

getCallSignature

protected String getCallSignature(SqlValidator validator,
                                  SqlValidatorScope scope)
Returns a string describing the actual argument types of a call, e.g. "SUBSTR(VARCHAR(12), NUMBER(3,2), INTEGER)".


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

isName

public boolean isName(String name)
Tests whether operator name matches supplied value.

Parameters:
name - Test string
Returns:
whether operator name matches parameter

isCountStar

public boolean isCountStar()
Test to see if it is the function COUNT(*)

Returns:
boolean true if function call to COUNT(*)

getFunctionQuantifier

public SqlLiteral getFunctionQuantifier()