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

pack-priv Class VirtualColumnNode

extends ValueNode
Class Inheritance
Imports
org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.types.DataTypeDescriptor

A VirtualColumnNode represents a virtual column reference to a column in a row returned by an underlying ResultSetNode. The underlying column could be in a base table, view (which could expand into a complex expression), subquery in the FROM clause, temp table, expression result, etc. By the time we get to code generation, all VirtualColumnNodes should stand only for references to columns in a base table within a FromBaseTable.

Field Summary

Modifier and TypeField and Description
pack-priv int
private boolean
private ResultColumn
private ResultSetNode
Inherited from org.apache.derby.impl.sql.compile.ValueNode:
transformed

Constructor Summary

AccessConstructor and Description
pack-priv
VirtualColumnNode(ResultSetNode
The ResultSetNode where the value is originating
sourceResultSet
,
ResultColumn
The ResultColumn where the value is originating
sourceColumn
,
int
The columnId within the current Row
columnId
,
ContextManager
The context manager
cm
)

Constructor for a VirtualColumnNode.

Method Summary

Modifier and TypeMethod and Description
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.

ColumnNode's are against the current row in the system.

pack-priv boolean

Returns:

Whether or not this VCN is a correlated reference.
getCorrelated
()

Return whether or not this VCN is a correlated reference.

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.

pack-priv String

Returns:

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

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

Get the name of the schema the ResultColumn's table is in, if any.

pack-priv ResultColumn

Returns:

ResultSetNode
getSourceColumn
()

Return the ResultColumn that is the source of this VirtualColumnNode.

pack-priv ResultColumn

Returns:

ResultSetNode
getSourceResultColumn
()

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

Return the ResultColumn that is the source of this VirtualColumnNode.

pack-priv ResultSetNode

Returns:

ResultSetNode
getSourceResultSet
()

Return the ResultSetNode that is the source of this VirtualColumnNode.

pack-priv String

Returns:

A String containing the name of the table the Column is in. If the column is not in a table (i.e. is a derived column), it returns NULL.
getTableName
()

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

Get the name of the table the ResultColumn is in, if any.

public final DataTypeDescriptor

Returns:

The DataTypeServices from this Node. This may be null if the node isn't bound yet.
getTypeServices
()

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

Get the DataTypeServices from this Node.

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.

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 void
setCorrelated()

Mark this VCN as a reference to a correlated column.

public final void
setType(DataTypeDescriptor
The DataTypeServices to set in this ValueNode
dtd
)

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

Set the DataTypeServices for this ValueNode.

public boolean

Returns:

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

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

Return whether or not the ResultColumn is wirtable by a positioned update.

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

Field Detail

columnIdback to summary
pack-priv int columnId
correlatedback to summary
private boolean correlated
sourceColumnback to summary
private ResultColumn sourceColumn
sourceResultSetback to summary
private ResultSetNode sourceResultSet

Constructor Detail

VirtualColumnNodeback to summary
pack-priv VirtualColumnNode(ResultSetNode sourceResultSet, ResultColumn sourceColumn, int columnId, ContextManager cm) throws StandardException

Constructor for a VirtualColumnNode.

Parameters
sourceResultSet:ResultSetNode

The ResultSetNode where the value is originating

sourceColumn:ResultColumn

The ResultColumn where the value is originating

columnId:int

The columnId within the current Row

cm:ContextManager

The context manager

Method Detail

generateExpressionback to summary
pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

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

ColumnNode's are against 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
getCorrelatedback to summary
pack-priv boolean getCorrelated()

Return whether or not this VCN is a correlated reference.

Returns:boolean

Whether or not this VCN is a correlated reference.

getOrderableVariantTypeback to summary
protected int getOrderableVariantType() throws StandardException

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
Exceptions
StandardException:
thrown on error
getSchemaNameback to summary
pack-priv String getSchemaName() throws StandardException

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

Get the name of the schema the ResultColumn's table is in, if any. The return value will be null if the user did not supply a schema 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

Returns:String

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

Annotations
@Override
getSourceColumnback to summary
pack-priv ResultColumn getSourceColumn()

Return the ResultColumn that is the source of this VirtualColumnNode.

Returns:ResultColumn

ResultSetNode

getSourceResultColumnback to summary
pack-priv ResultColumn getSourceResultColumn()

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

Return the ResultColumn that is the source of this VirtualColumnNode.

Returns:ResultColumn

ResultSetNode

Annotations
@Override
getSourceResultSetback to summary
pack-priv ResultSetNode getSourceResultSet()

Return the ResultSetNode that is the source of this VirtualColumnNode.

Returns:ResultSetNode

ResultSetNode

getTableNameback to summary
pack-priv String getTableName()

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

Get the name of the table the ResultColumn is in, if any. 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

A String containing the name of the table the Column is in. If the column is not in a table (i.e. is a derived column), it returns NULL.

Annotations
@Override
getTypeServicesback to summary
public final DataTypeDescriptor getTypeServices()

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

Get the DataTypeServices from this Node.

Returns:DataTypeDescriptor

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

Annotations
@Override
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.

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
setCorrelatedback to summary
pack-priv void setCorrelated()

Mark this VCN as a reference to a correlated column. (It's source resultSet is an outer ResultSet.

setTypeback to summary
public final void setType(DataTypeDescriptor dtd) throws StandardException

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

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

Set the DataTypeServices for this ValueNode. This method is overridden in ParameterNode.

Parameters
dtd:DataTypeDescriptor

The DataTypeServices to set in this ValueNode

Annotations
@Override
updatableByCursorback to summary
public boolean updatableByCursor()

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

Return whether or not the ResultColumn is wirtable by a positioned update.

Returns:boolean

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

Annotations
@Override