Top Description Inners Fields Constructors Methods
org.apache.derby.impl.sql.compile

public Class ColumnReference

extends ValueNode
Class Inheritance
Imports
java.util.List, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.sql.compile.Visitor, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.store.access.Qualifier, org.apache.derby.iapi.types.DataTypeDescriptor, org.apache.derby.iapi.util.JBitSet

A ColumnReference represents a column in the query tree. The parser generates a ColumnReference for each column reference. A column reference could be a column in a base table, a column in a view (which could expand into a complex expression), or a column in a subquery in the FROM clause.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ColumnReference.RemapInfo

Helper class to keep track of remap data when a ColumnReference is remapped multiple times.

Field Summary

Modifier and TypeField and Description
private String
private int
_mergeTableID

Columns mentioned by MERGE statements need to be associated the SOURCE or TARGET table

private int
private ResultColumn
private int
private TableName
private int
columnNumber

The column number in the underlying FromTable.

private int
public static final int
public static final int
public static final int
private int
private String
private ArrayList<ColumnReference.RemapInfo>
private boolean
private boolean
private boolean
private ResultColumn
source

This is where the value for this column reference will be coming from.

private int
private int
tableNumber

The FromTable this column reference is bound to.

private int
Inherited from org.apache.derby.impl.sql.compile.ValueNode:
transformed

Constructor Summary

AccessConstructor and Description
pack-priv
ColumnReference(String
The name of the column being referenced
columnName
,
TableName
The qualification for the column
tableName
,
int
begin position of token for the column name identifier from parser.
tokBeginOffset
,
int
end position of token for the column name identifier from parser.
tokEndOffset
,
ContextManager
The context manager
cm
)

Constructor.

pack-priv
ColumnReference(String
The name of the column being referenced
columnName
,
TableName
The qualification for the column
tableName
,
ContextManager
The context manager
cm
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.acceptChildren.

Accept a visitor on all child nodes.

pack-priv ColumnReference

Returns:

The new top of the expression tree.
bindExpression
(FromList
The FROM list for the query this expression is in, for binding columns.
fromList
,
SubqueryList
The subquery list being built as we find SubqueryNodes
subqueryList
,
List<AggregateNode>
The aggregate list being built as we find AggregateNodes
aggregates
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.bindExpression.

Bind this expression.

pack-priv boolean

Returns:

boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode or a ConstantNode.
categorize
(JBitSet
JBitSet with bit map of referenced FromTables
referencedTabs
,
boolean
Whether or not to consider method calls, field references and conditional nodes when building bit map
simplePredsOnly
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.categorize.

Categorize this predicate.

pack-priv boolean
constantExpression(PredicateList whereClause)

Overrides org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

Return whether or not this expression tree represents a constant value.

pack-priv void
copyFields(ColumnReference
The ColumnReference to copy from.
oldCR
)

Copy all of the "appropriate fields" for a shallow copy.

pack-priv void
generateExpression(ExpressionClassBuilder
The ExpressionClassBuilder for the class being built
acb
,
MethodBuilder
The method the expression will go into
mb
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.generateExpression.

ColumnReference's are to the current row in the system.

pack-priv ValueNode

Returns:

ValueNode A clone of this node.
getClone
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getClone.

Return a clone of this node.

public String

Returns:

The name of this column
getColumnName
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getColumnName.

Get the name of this column

pack-priv int

Returns:

int The column number for this ColumnReference
getColumnNumber
()

Get the column number for this ColumnReference.

pack-priv boolean

Returns:

Whether or not this CR is correlated.
getCorrelated
()

Return whether or not this CR is correlated.

pack-priv boolean

Returns:

boolean Whether or not this node was generated to replace an aggregate in the user's SELECT.
getGeneratedToReplaceAggregate
()

Determine whether or not this node was generated to replace an aggregate in the user's SELECT.

pack-priv boolean

Returns:

boolean Whether or not this node was generated to replace a window function call in the user's SELECT.
getGeneratedToReplaceWindowFunctionCall
()

Determine whether or not this node was generated to replace a window function call in the user's SELECT.

pack-priv int
getMergeTableID()

Get the MERGE table (SOURCE or TARGET) associated with this column

private int

Returns:

The nesting level for this CR.
getNestingLevel
()

Get the nesting level for this CR.

protected int

Returns:

The variant type for the underlying expression.
getOrderableVariantType
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getOrderableVariantType.

Return the variant type for the underlying expression.

public TableName

Returns:

the column's table name.
getQualifiedTableName
()

Return the table name as the node it is.

pack-priv String

Returns:

The user-supplied schema name of this column. Null if no user- supplied name.
getSchemaName
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getSchemaName.

Get the user-supplied schema name of this column.

pack-priv ResultColumn

Returns:

The source of this columnReference
getSource
()

Get the source this columnReference

pack-priv int

Returns:

The source level for this CR.
getSourceLevel
()

Get the source level for this CR.

pack-priv ResultColumn
protected ResultSetNode

Returns:

The source result set for this ColumnReference; null if there is no source result set.
getSourceResultSet
(int[]
Place to store the position of the column to which this ColumnReference points (position is w.r.t the source result set).
colNum
)

Find the source result set for this ColumnReference and return it.

pack-priv String

Returns:

The name of the schema for Column's base table. If the column is not in a schema (i.e. is a derived column), it returns NULL.
getSourceSchemaName
()

Get the name of the schema for the Column's base table, if any.

pack-priv String

Returns:

The name of the base table that this column comes from. Null if not a ColumnReference.
getSourceTableName
()

Get the name of the underlying(base) table this column comes from, if any.

pack-priv String

Returns:

The column name in the form [[schema.]table.]column
getSQLColumnName
()

Get the column name for purposes of error messages or debugging.

pack-priv String

Returns:

The user-supplied name of this column. Null if no user- supplied name.
getTableName
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getTableName.

Get the user-supplied table name of this column.

pack-priv int

Returns:

int The table number for this ColumnReference
getTableNumber
()

Get the table number for this ColumnReference.

pack-priv void
getTablesReferenced(JBitSet
The table map.
refs
)

Update the table map to reflect the source of this CR.

pack-priv DataTypeDescriptor
getTypeServices()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getTypeServices.

The type of a ColumnReference is the type of its source unless the source is null then it is the type that has been set on this node.

protected boolean

Returns:

Whether or not this ColumnReference has been remapped.
hasBeenRemapped
()

Returns true if this ColumnReference has been remapped; false otherwise.

pack-priv boolean

Returns:

boolean Whether or not this expression tree is cloneable.
isCloneable
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isCloneable.

Return whether or not this expression tree is cloneable.

pack-priv boolean
isEquivalent(ValueNode
the node to compare this ValueNode against.
o
)

Implements abstract org.apache.derby.impl.sql.compile.ValueNode.isEquivalent.

Tests if this node is equivalent to the specified ValueNode.

protected boolean
isScoped()

Return whether or not this ColumnReference is scoped.

protected void
markAsScoped()

Mark this column reference as "scoped", which means that it was created (as a clone of another ColumnReference) to serve as the left or right operand of a scoped predicate.

pack-priv void
markGeneratedToReplaceAggregate()

Mark this node as being generated to replace an aggregate.

pack-priv void
markGeneratedToReplaceWindowFunctionCall()

Mark this node as being generated to replace a window function call.

pack-priv boolean

Returns:

Whether or not the source of this ColumnReference is itself a ColumnReference.
pointsToColumnReference
()

Return whether or not the source of this ColumnReference is itself a ColumnReference.

private String
prettyPrintMergeTableID(int mergeTableID)

pack-priv void
printSubNodes(int
The depth of this node in the tree
depth
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.printSubNodes.

Prints the sub-nodes of this object.

pack-priv ValueNode

Returns:

The modified expression
putAndsOnTop
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.putAndsOnTop.

Do the 1st step in putting an expression into conjunctive normal form.

pack-priv void
remapColumnReferences()

Remap all of the ColumnReferences in this expression tree to point to the ResultColumn that is 1 level under their current source ResultColumn.

pack-priv ValueNode

Returns:

ValueNode The remapped expression tree.
remapColumnReferencesToExpressions
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.remapColumnReferencesToExpressions.

Remap all ColumnReferences in this tree to be clones of the underlying expression.

pack-priv void
setColumnNumber(int
The new column number.
colNum
)

Set the column number for this ColumnReference.

pack-priv void
setMergeTableID(int mergeTableID)

Associate this column with a SOURCE or TARGET table of a MERGE statement

pack-priv void
setNestingLevel(int
The Nesting level at which the CR appears.
nestingLevel
)

Set the nesting level for this CR.

pack-priv void
pack-priv void
setSource(ResultColumn
The source of this columnReference
source
)

Set the source this columnReference

pack-priv void
setSourceLevel(int
The Nesting level of the source of the CR.
sourceLevel
)

Set the source level for this CR.

pack-priv void
setTableNumber(int
The table number this ColumnReference will refer to
tableNumber
)

Set this ColumnReference to refer to the given table number.

public String

Returns:

This object as a String
toString
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.toString.

Convert this object to a String.

pack-priv void
public boolean

Returns:

TRUE, if the column is a base column of a table and is writable by cursor.
updatableByCursor
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.updatableByCursor.

Is the column wirtable by the cursor or not.

Inherited from org.apache.derby.impl.sql.compile.ValueNode:
bindExpressionchangeToCNFcheckIsBooleancheckTopPredicatesForEqualsConditionscopyFieldseliminateNotsevaluateConstantExpressionsgenEqualsFalseTreegenerategenIsNullTreegenSQLJavaSQLTreegetConstantValueAsObjectgetDataValueFactorygetTablesReferencedgetTransformedgetTypeCompilergetTypeIdisBinaryEqualsOperatorNodeisBooleanFalseisBooleanTrueisConstantExpressionisInListProbeNodeisParameterNodeisRelationalOperatorisSameNodeKindoptimizableEqualityNodepreprocessrequiresTypeFromContextselectivitysetCollationInfosetCollationInfosetCollationUsingCompilationSchemasetCollationUsingCompilationSchemasetNullabilitysetTransformedsetTypesetTypesetTypeverifyChangeToCNFverifyEliminateNotsverifyPutAndsOnTop

Field Detail

_columnNameback to summary
private String _columnName
_mergeTableIDback to summary
private int _mergeTableID

Columns mentioned by MERGE statements need to be associated the SOURCE or TARGET table

_origColumnNumberback to summary
private int _origColumnNumber
_origSourceback to summary
private ResultColumn _origSource
_origTableNumberback to summary
private int _origTableNumber
_qualifiedTableNameback to summary
private TableName _qualifiedTableName
columnNumberback to summary
private int columnNumber

The column number in the underlying FromTable. But note source.

See Also
source
columnNumberBeforeFlatteningback to summary
private int columnNumberBeforeFlattening
MERGE_SOURCEback to summary
public static final int MERGE_SOURCE
MERGE_TARGETback to summary
public static final int MERGE_TARGET
MERGE_UNKNOWNback to summary
public static final int MERGE_UNKNOWN
nestingLevelback to summary
private int nestingLevel
origNameback to summary
private String origName
remapsback to summary
private ArrayList<ColumnReference.RemapInfo> remaps
replacesAggregateback to summary
private boolean replacesAggregate
replacesWindowFunctionCallback to summary
private boolean replacesWindowFunctionCall
scopedback to summary
private boolean scoped
sourceback to summary
private ResultColumn source

This is where the value for this column reference will be coming from. Note that for join nodes, tableNumber/columnNumber will point to the column in the left or right join participant FromTable, whereas source will be bound to the RC in the result column list of the join node. See also the comment at the end of JoinNode#getMatchingColumn.

See Also
JoinNode#getMatchingColumn, columnNumber, tableNumber
sourceLevelback to summary
private int sourceLevel
tableNumberback to summary
private int tableNumber

The FromTable this column reference is bound to.

tableNumberBeforeFlatteningback to summary
private int tableNumberBeforeFlattening

Constructor Detail

ColumnReferenceback to summary
pack-priv ColumnReference(String columnName, TableName tableName, int tokBeginOffset, int tokEndOffset, ContextManager cm)

Constructor. This one is called by the parser where we could be dealing with delimited identifiers.

Parameters
columnName:String

The name of the column being referenced

tableName:TableName

The qualification for the column

tokBeginOffset:int

begin position of token for the column name identifier from parser.

tokEndOffset:int

end position of token for the column name identifier from parser.

cm:ContextManager

The context manager

ColumnReferenceback to summary
pack-priv ColumnReference(String columnName, TableName tableName, ContextManager cm)

Constructor.

Parameters
columnName:String

The name of the column being referenced

tableName:TableName

The qualification for the column

cm:ContextManager

The context manager

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.acceptChildren.

Doc from org.apache.derby.impl.sql.compile.QueryTreeNode.acceptChildren.

Accept a visitor on all child nodes. All sub-classes that add fields that should be visited, should override this method and call accept(v) on all visitable fields, as well as super.acceptChildren(v) to make sure all visitable fields defined by the super-class are accepted too.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on errors raised by the visitor
bindExpressionback to summary
pack-priv ColumnReference bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.bindExpression.

Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.

Note

We must explicitly check for a null FromList here, column reference without a FROM list, as the grammar allows the following: insert into t1 values(c1)

Parameters
fromList:FromList

The FROM list for the query this expression is in, for binding columns.

subqueryList:SubqueryList

The subquery list being built as we find SubqueryNodes

aggregates:List<AggregateNode>

The aggregate list being built as we find AggregateNodes

Returns:ColumnReference

The new top of the expression tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
categorizeback to summary
pack-priv boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)

Overrides org.apache.derby.impl.sql.compile.ValueNode.categorize.

Categorize this predicate. Initially, this means building a bit map of the referenced tables for each predicate. If the source of this ColumnReference (at the next underlying level) is not a ColumnReference or a VirtualColumnNode then this predicate will not be pushed down. For example, in: select * from (select 1 from s) a (x) where x = 1 we will not push down x = 1.

Note

It would be easy to handle the case of a constant, but if the inner SELECT returns an arbitrary expression, then we would have to copy that tree into the pushed predicate, and that tree could contain subqueries and method calls. Also, don't allow a predicate to be pushed down if it contains a ColumnReference that replaces an aggregate. This can happen if the aggregate is in the HAVING clause. In this case, we would be pushing the predicate into the SelectNode that evaluates the aggregate, which doesn't make sense, since the having clause is supposed to be applied to the result of the SelectNode. This also goes for column references that replaces a window function. RESOLVE - revisit this issue once we have views.

Parameters
referencedTabs:JBitSet

JBitSet with bit map of referenced FromTables

simplePredsOnly:boolean

Whether or not to consider method calls, field references and conditional nodes when building bit map

Returns:boolean

boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode or a ConstantNode.

Annotations
@Override
constantExpressionback to summary
pack-priv boolean constantExpression(PredicateList whereClause)

Overrides org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

Doc from org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

Return whether or not this expression tree represents a constant value. In this case, "constant" means that it will always evaluate to the same thing, even if it includes columns. A column is constant if it is compared to a constant expression.

Returns:boolean

True means this expression tree represents a constant value.

Annotations
@Override
See Also
ValueNode#constantExpression
copyFieldsback to summary
pack-priv void copyFields(ColumnReference oldCR) throws StandardException

Copy all of the "appropriate fields" for a shallow copy.

Parameters
oldCR:ColumnReference

The ColumnReference to copy from.

Exceptions
StandardException:
Thrown on error
generateExpressionback to summary
pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.generateExpression.

ColumnReference's are to the current row in the system. This lets us generate a faster get that simply returns the column from the current row, rather than getting the value out and returning that, only to have the caller (in the situations needed) stuffing it back into a new column holder object. We will assume the general generate() path is for getting the value out, and use generateColumn() when we want to keep the column wrapped.

Parameters
acb:ExpressionClassBuilder

Doc from org.apache.derby.impl.sql.compile.ValueNode.generateExpression.

The ExpressionClassBuilder for the class being built

mb:MethodBuilder

Doc from org.apache.derby.impl.sql.compile.ValueNode.generateExpression.

The method the expression will go into

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getCloneback to summary
pack-priv ValueNode getClone() throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.getClone.

Return a clone of this node.

Returns:ValueNode

ValueNode A clone of this node.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getColumnNameback to summary
public String getColumnName()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getColumnName.

Get the name of this column

Returns:String

The name of this column

Annotations
@Override
getColumnNumberback to summary
pack-priv int getColumnNumber()

Get the column number for this ColumnReference.

Returns:int

int The column number for this ColumnReference

getCorrelatedback to summary
pack-priv boolean getCorrelated()

Return whether or not this CR is correlated.

Returns:boolean

Whether or not this CR is correlated.

getGeneratedToReplaceAggregateback to summary
pack-priv boolean getGeneratedToReplaceAggregate()

Determine whether or not this node was generated to replace an aggregate in the user's SELECT.

Returns:boolean

boolean Whether or not this node was generated to replace an aggregate in the user's SELECT.

getGeneratedToReplaceWindowFunctionCallback to summary
pack-priv boolean getGeneratedToReplaceWindowFunctionCall()

Determine whether or not this node was generated to replace a window function call in the user's SELECT.

Returns:boolean

boolean Whether or not this node was generated to replace a window function call in the user's SELECT.

getMergeTableIDback to summary
pack-priv int getMergeTableID()

Get the MERGE table (SOURCE or TARGET) associated with this column

getNestingLevelback to summary
private int getNestingLevel()

Get the nesting level for this CR.

Returns:int

The nesting level for this CR.

getOrderableVariantTypeback to summary
protected int getOrderableVariantType()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getOrderableVariantType.

Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (method calls and non-static field access) SCAN_INVARIANT - invariant within a scan (column references from outer tables) QUERY_INVARIANT - invariant within the life of a query (constant expressions)

Returns:int

The variant type for the underlying expression.

Annotations
@Override
getQualifiedTableNameback to summary
public TableName getQualifiedTableName()

Return the table name as the node it is.

Returns:TableName

the column's table name.

getSchemaNameback to summary
pack-priv String getSchemaName()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getSchemaName.

Get the user-supplied schema name of this column. This will be null if the user did not supply a name (for example, select t.a from t). Another example for null return value (for example, select b.a from t as b). But for following query select app.t.a from t, this will return APP Code generation of aggregate functions relies on this method

Returns:String

The user-supplied schema name of this column. Null if no user- supplied name.

Annotations
@Override
getSourceback to summary
pack-priv ResultColumn getSource()

Get the source this columnReference

Returns:ResultColumn

The source of this columnReference

getSourceLevelback to summary
pack-priv int getSourceLevel()

Get the source level for this CR.

Returns:int

The source level for this CR.

getSourceResultColumnback to summary
pack-priv ResultColumn getSourceResultColumn()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getSourceResultColumn.

Doc from org.apache.derby.impl.sql.compile.ValueNode.getSourceResultColumn.

Get the source for this ValueNode.

Returns:ResultColumn

The source of this ValueNode, null if this node is not sourced by a column.

Annotations
@Override
getSourceResultSetback to summary
protected ResultSetNode getSourceResultSet(int[] colNum) throws StandardException

Find the source result set for this ColumnReference and return it. Also, when the source result set is found, return the position (within the source result set's RCL) of the column referenced by this ColumnReference. The position is returned vai the colNum parameter.

Parameters
colNum:int[]

Place to store the position of the column to which this ColumnReference points (position is w.r.t the source result set).

Returns:ResultSetNode

The source result set for this ColumnReference; null if there is no source result set.

getSourceSchemaNameback to summary
pack-priv String getSourceSchemaName() throws StandardException

Get the name of the schema for the Column's base table, if any. Following example queries will all return APP (assuming user is in schema APP) select t.a from t select b.a from t as b select app.t.a from t

Returns:String

The name of the schema for Column's base table. If the column is not in a schema (i.e. is a derived column), it returns NULL.

getSourceTableNameback to summary
pack-priv String getSourceTableName()

Get the name of the underlying(base) table this column comes from, if any. Following example queries will all return T select a from t select b.a from t as b select t.a from t

Returns:String

The name of the base table that this column comes from. Null if not a ColumnReference.

getSQLColumnNameback to summary
pack-priv String getSQLColumnName()

Get the column name for purposes of error messages or debugging. This returns the column name as used in the SQL statement. Thus if it was qualified with a table, alias name that will be included.

Returns:String

The column name in the form [[schema.]table.]column

getTableNameback to summary
pack-priv String getTableName()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getTableName.

Get the user-supplied table name of this column. This will be null if the user did not supply a name (for example, select a from t). The method will return B for this example, select b.a from t as b The method will return T for this example, select t.a from t

Returns:String

The user-supplied name of this column. Null if no user- supplied name.

Annotations
@Override
getTableNumberback to summary
pack-priv int getTableNumber()

Get the table number for this ColumnReference.

Returns:int

int The table number for this ColumnReference

getTablesReferencedback to summary
pack-priv void getTablesReferenced(JBitSet refs)

Update the table map to reflect the source of this CR.

Parameters
refs:JBitSet

The table map.

getTypeServicesback to summary
pack-priv DataTypeDescriptor getTypeServices()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getTypeServices.

The type of a ColumnReference is the type of its source unless the source is null then it is the type that has been set on this node.

Returns:DataTypeDescriptor

Doc from org.apache.derby.impl.sql.compile.ValueNode.getTypeServices.

The DataTypeServices from this ValueNode. This may be null if the node isn't bound yet.

Annotations
@Override
hasBeenRemappedback to summary
protected boolean hasBeenRemapped()

Returns true if this ColumnReference has been remapped; false otherwise.

Returns:boolean

Whether or not this ColumnReference has been remapped.

isCloneableback to summary
pack-priv boolean isCloneable()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isCloneable.

Return whether or not this expression tree is cloneable.

Returns:boolean

boolean Whether or not this expression tree is cloneable.

Annotations
@Override
isEquivalentback to summary
pack-priv boolean isEquivalent(ValueNode o) throws StandardException

Implements abstract org.apache.derby.impl.sql.compile.ValueNode.isEquivalent.

Doc from org.apache.derby.impl.sql.compile.ValueNode.isEquivalent.

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:

  • The two ValueNodes must be of the same node type to be considered equivalent. e.g.: CastNode vs. CastNode - equivalent (if their args also match), ColumnReference vs CastNode - not equivalent.
  • If node P contains other ValueNode(s) and so on, those node(s) must also be of the same node type to be considered equivalent.
  • If node P takes a parameter list, then the number of arguments and its arguments for the two nodes must also match to be considered equivalent. e.g.: CAST(c1 as INTEGER) vs CAST(c1 as SMALLINT), they are not equivalent.
  • When comparing SQL NULLs in this context, they are considered to be equivalent.
  • If this does not apply or it is determined that the two nodes are not equivalent then the derived class of this method should return false; otherwise, return true.
Parameters
o:ValueNode

the node to compare this ValueNode against.

Returns:boolean

true if the two nodes are equivalent, false otherwise.

isScopedback to summary
protected boolean isScoped()

Return whether or not this ColumnReference is scoped.

markAsScopedback to summary
protected void markAsScoped()

Mark this column reference as "scoped", which means that it was created (as a clone of another ColumnReference) to serve as the left or right operand of a scoped predicate.

markGeneratedToReplaceAggregateback to summary
pack-priv void markGeneratedToReplaceAggregate()

Mark this node as being generated to replace an aggregate. (Useful for replacing aggregates in the HAVING clause with column references to the matching aggregate in the user's SELECT.

markGeneratedToReplaceWindowFunctionCallback to summary
pack-priv void markGeneratedToReplaceWindowFunctionCall()

Mark this node as being generated to replace a window function call.

pointsToColumnReferenceback to summary
pack-priv boolean pointsToColumnReference()

Return whether or not the source of this ColumnReference is itself a ColumnReference.

Returns:boolean

Whether or not the source of this ColumnReference is itself a ColumnReference.

prettyPrintMergeTableIDback to summary
private String prettyPrintMergeTableID(int mergeTableID)
printSubNodesback to summary
pack-priv void printSubNodes(int depth)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.printSubNodes.

Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Parameters
depth:int

The depth of this node in the tree

Annotations
@Override
putAndsOnTopback to summary
pack-priv ValueNode putAndsOnTop() throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.putAndsOnTop.

Do the 1st step in putting an expression into conjunctive normal form. This step ensures that the top level of the expression is a chain of AndNodes.

Returns:ValueNode

The modified expression

Annotations
@Override
Exceptions
StandardException:
Thrown on error
remapColumnReferencesback to summary
pack-priv void remapColumnReferences()

Remap all of the ColumnReferences in this expression tree to point to the ResultColumn that is 1 level under their current source ResultColumn. This is useful for pushing down single table predicates.

Resolve

Once we start pushing join clauses, we will need to walk the ResultColumn/VirtualColumnNode chain for them to remap the references.

remapColumnReferencesToExpressionsback to summary
pack-priv ValueNode remapColumnReferencesToExpressions() throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.remapColumnReferencesToExpressions.

Remap all ColumnReferences in this tree to be clones of the underlying expression.

Returns:ValueNode

ValueNode The remapped expression tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
setColumnNumberback to summary
pack-priv void setColumnNumber(int colNum)

Set the column number for this ColumnReference. This is used when scoping predicates for pushdown.

Parameters
colNum:int

The new column number.

setMergeTableIDback to summary
pack-priv void setMergeTableID(int mergeTableID)

Associate this column with a SOURCE or TARGET table of a MERGE statement

setNestingLevelback to summary
pack-priv void setNestingLevel(int nestingLevel)

Set the nesting level for this CR. (The nesting level at which the CR appears.)

Parameters
nestingLevel:int

The Nesting level at which the CR appears.

setQualifiedTableNameback to summary
pack-priv void setQualifiedTableName(TableName tableName)
setSourceback to summary
pack-priv void setSource(ResultColumn source)

Set the source this columnReference

Parameters
source:ResultColumn

The source of this columnReference

setSourceLevelback to summary
pack-priv void setSourceLevel(int sourceLevel)

Set the source level for this CR. (The nesting level of the source of the CR.)

Parameters
sourceLevel:int

The Nesting level of the source of the CR.

setTableNumberback to summary
pack-priv void setTableNumber(int tableNumber)

Set this ColumnReference to refer to the given table number.

Parameters
tableNumber:int

The table number this ColumnReference will refer to

toStringback to summary
public String toString()

Overrides org.apache.derby.impl.sql.compile.ValueNode.toString.

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

Returns:String

This object as a String

Annotations
@Override
unRemapColumnReferencesback to summary
pack-priv void unRemapColumnReferences()
updatableByCursorback to summary
public boolean updatableByCursor()

Overrides org.apache.derby.impl.sql.compile.ValueNode.updatableByCursor.

Is the column wirtable by the cursor or not. (ie, is it in the list of FOR UPDATE columns list)

Returns:boolean

TRUE, if the column is a base column of a table and is writable by cursor.

Annotations
@Override
org.apache.derby.impl.sql.compile back to summary

private Class ColumnReference.RemapInfo

extends Object
Class Inheritance

Helper class to keep track of remap data when a ColumnReference is remapped multiple times. This allows the CR to be UN- remapped multiple times, as well.

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv int
pack-priv ResultColumn
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
RemapInfo(int cNum, int tNum, String cName, ResultColumn rc)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
pack-priv int
pack-priv ResultColumn
pack-priv int
pack-priv void
pack-priv void
setColNumber(int cNum)

pack-priv void
pack-priv void
setTableNumber(int tNum)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

colNameback to summary
pack-priv String colName
colNumback to summary
pack-priv int colNum
sourceback to summary
pack-priv ResultColumn source
tableNumback to summary
pack-priv int tableNum

Constructor Detail

RemapInfoback to summary
pack-priv RemapInfo(int cNum, int tNum, String cName, ResultColumn rc)

Method Detail

getColumnNameback to summary
pack-priv String getColumnName()
getColumnNumberback to summary
pack-priv int getColumnNumber()
getSourceback to summary
pack-priv ResultColumn getSource()
getTableNumberback to summary
pack-priv int getTableNumber()
setColNameback to summary
pack-priv void setColName(String cName)
setColNumberback to summary
pack-priv void setColNumber(int cNum)
setSourceback to summary
pack-priv void setSource(ResultColumn rc)
setTableNumberback to summary
pack-priv void setTableNumber(int tNum)