com.akiban.sql.parser
Class ResultColumn

java.lang.Object
  extended by com.akiban.sql.parser.QueryTreeNode
      extended by com.akiban.sql.parser.ValueNode
          extended by com.akiban.sql.parser.ResultColumn
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
AllResultColumn

public class ResultColumn
extends ValueNode

A ResultColumn represents a result column in a SELECT, INSERT, or UPDATE statement. In a SELECT statement, the result column just represents an expression in a row being returned to the client. For INSERT and UPDATE statements, the result column represents an column in a stored table. So, a ResultColumn has to be bound differently depending on the type of statement it appears in.

The type of the ResultColumn can differ from its underlying expression, for example in certain joins the ResultColumn can be nullable even if its underlying column is not. In an INSERT or UPDATE the ResultColumn will represent the type of the column in the table, the type of the underlying expresion will be the type of the source of the value to be insert or updated. The method columnTypeAndLengthMatch() can be used to detect when normalization is required between the expression and the tyoe of ResultColumn. This class does not implement any type normalization (conversion), this is typically handled by a NormalizeResultSetNode.


Field Summary
 
Fields inherited from class com.akiban.sql.parser.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
 
Constructor Summary
ResultColumn()
           
 
Method Summary
 void adjustVirtualColumnId(int adjust)
          Adjust the virtualColumnId for this ResultColumn by the specified amount
 void copyFrom(QueryTreeNode node)
          Fill this node with a deep copy of the given node.
 int getColumnPosition()
           
 ValueNode getExpression()
          Get the expression in this ResultColumn.
 String getName()
          The following methods implement the ResultColumnDescriptor interface.
 ColumnReference getReference()
           
 String getSchemaName()
          This returns the user-supplied schema name of the column.
 String getTableName()
          This returns the user-supplied table name of the column.
 TableName getTableNameObject()
           
 int getVirtualColumnId()
          Get the virtualColumnId for this ResultColumn
 void init(Object arg1, Object arg2)
          Different types of initializer parameters indicate different types of initialization.
 boolean isDefaultColumn()
          Returns TRUE if the ResultColumn is standing in for a DEFAULT keyword in an insert/update statement.
 boolean isEquivalent(ValueNode o)
          Tests if this node is equivalent to the specified ValueNode.
 boolean isNameGenerated()
          Is the name for this ResultColumn generated?
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 void setDefaultColumn(boolean value)
           
 void setExpression(ValueNode expression)
          Set the expression in this ResultColumn.
 void setName(String name)
          Set the name in this ResultColumn.
 void setNameGenerated(boolean value)
          Set that this result column name is generated.
 void setVirtualColumnId(int id)
          Set the virtualColumnId for this ResultColumn
 String toString()
          Convert this object to a String.
 
Methods inherited from class com.akiban.sql.parser.ValueNode
getColumnName, getSourceResultColumn, getType, getTypeId, init, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isConstantExpression, isInListProbeNode, isParameterNode, isRelationalOperator, isSameNodeType, setNullability, setType
 
Methods inherited from class com.akiban.sql.parser.QueryTreeNode
accept, convertDefaultNode, debugFlush, debugPrint, formatNodeString, getBeginOffset, getDebugOutput, getEndOffset, getNodeFactory, getNodeType, getNullNode, getParserContext, getStatementType, getUserData, init, init, init, init, init, init, init, init, init, init, init, init, isInstanceOf, makeTableName, makeTableName, nodeHeader, printLabel, setBeginOffset, setDebugOutput, setEndOffset, setNodeType, setParserContext, setUserData, stackPrint, treePrint, treePrint, treePrint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResultColumn

public ResultColumn()
Method Detail

init

public void init(Object arg1,
                 Object arg2)
          throws StandardException
Different types of initializer parameters indicate different types of initialization. Parameters may be:

- OR -

- OR -

- OR -

Overrides:
init in class QueryTreeNode
Throws:
StandardException - Thrown on error

copyFrom

public void copyFrom(QueryTreeNode node)
              throws StandardException
Fill this node with a deep copy of the given node.

Overrides:
copyFrom in class ValueNode
Throws:
StandardException

isDefaultColumn

public boolean isDefaultColumn()
Returns TRUE if the ResultColumn is standing in for a DEFAULT keyword in an insert/update statement.


setDefaultColumn

public void setDefaultColumn(boolean value)

getName

public String getName()
The following methods implement the ResultColumnDescriptor interface. See the Language Module Interface for details.


getSchemaName

public String getSchemaName()
                     throws StandardException
Description copied from class: ValueNode
This returns the user-supplied schema name of the column. At this class level, it simply returns null. But, the subclasses of ValueNode will overwrite this method to return the user-supplied schema name. When the value node is in a result column of a select list, the user can request metadata information. The result column won't have a column descriptor, so we return some default information through the expression. This lets expressions that are simply columns return all of the info, and others use this supertype's default values.

Overrides:
getSchemaName in class ValueNode
Returns:
the default schema name for an expression -- null
Throws:
StandardException

getTableName

public String getTableName()
Description copied from class: ValueNode
This returns the user-supplied table name of the column. At this class level, it simply returns null. But, the subclasses of ValueNode will overwrite this method to return the user-supplied table name. When the value node is in a result column of a select list, the user can request metadata information. The result column won't have a column descriptor, so we return some default information through the expression. This lets expressions that are simply columns return all of the info, and others use this supertype's default values.

Overrides:
getTableName in class ValueNode
Returns:
the default table name for an expression -- null

getColumnPosition

public int getColumnPosition()

setExpression

public void setExpression(ValueNode expression)
Set the expression in this ResultColumn. This is useful in those cases where you don't know the expression in advance, like for INSERT statements with column lists, where the column list and SELECT or VALUES clause are parsed separately, and then have to be hooked up.

Parameters:
expression - The expression to be set in this ResultColumn

getExpression

public ValueNode getExpression()
Get the expression in this ResultColumn.

Returns:
ValueNode this.expression

setName

public void setName(String name)
Set the name in this ResultColumn. This is useful when you don't know the name at the time you create the ResultColumn, for example, in an insert-select statement, where you want the names of the result columns to match the table being inserted into, not the table they came from.

Parameters:
name - The name to set in this ResultColumn

isNameGenerated

public boolean isNameGenerated()
Is the name for this ResultColumn generated?


setNameGenerated

public void setNameGenerated(boolean value)
Set that this result column name is generated.


adjustVirtualColumnId

public void adjustVirtualColumnId(int adjust)
Adjust the virtualColumnId for this ResultColumn by the specified amount

Parameters:
adjust - The adjustment for the virtualColumnId

setVirtualColumnId

public void setVirtualColumnId(int id)
Set the virtualColumnId for this ResultColumn

Parameters:
id - The virtualColumnId for this ResultColumn

getVirtualColumnId

public int getVirtualColumnId()
Get the virtualColumnId for this ResultColumn

Returns:
virtualColumnId for this ResultColumn

toString

public String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class ValueNode
Returns:
This object as a String

printSubNodes

public void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Overrides:
printSubNodes in class QueryTreeNode
Parameters:
depth - The depth of this node in the tree

getTableNameObject

public TableName getTableNameObject()

getReference

public ColumnReference getReference()

isEquivalent

public boolean isEquivalent(ValueNode o)
                     throws StandardException
Description copied from class: ValueNode
Tests if this node is equivalent to the specified ValueNode. Two ValueNodes are considered equivalent if they will evaluate to the same value during query execution.

This method provides basic expression matching facility for the derived class of ValueNode and it is used by the language layer to compare the node structural form of the two expressions for equivalence at bind phase.

Note that it is not comparing the actual row values at runtime to produce a result; hence, when comparing SQL NULLs, they are considered to be equivalent and not unknown.

One usage case of this method in this context is to compare the select column expression against the group by expression to check if they are equivalent. e.g.:

SELECT c1+c2 FROM t1 GROUP BY c1+c2

In general, node equivalence is determined by the derived class of ValueNode. But they generally abide to the rules below:

Specified by:
isEquivalent in class ValueNode
Parameters:
o - the node to compare this ValueNode against.
Returns:
true if the two nodes are equivalent, false otherwise.
Throws:
StandardException


Copyright © 2013 Akiban Technologies, Inc. All rights reserved.