Class VirtualColumnNode
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.ValueNode
-
- org.apache.derby.impl.sql.compile.VirtualColumnNode
-
- All Implemented Interfaces:
Visitable
class VirtualColumnNode extends ValueNode
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
Fields Modifier and Type Field Description (package private) int
columnId
private boolean
correlated
private ResultColumn
sourceColumn
private ResultSetNode
sourceResultSet
-
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode
transformed
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description VirtualColumnNode(ResultSetNode sourceResultSet, ResultColumn sourceColumn, int columnId, ContextManager cm)
Constructor for a VirtualColumnNode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
ColumnNode's are against the current row in the system.(package private) boolean
getCorrelated()
Return whether or not this VCN is a correlated reference.protected int
getOrderableVariantType()
Return the variant type for the underlying expression.(package private) java.lang.String
getSchemaName()
Get the name of the schema the ResultColumn's table is in, if any.(package private) ResultColumn
getSourceColumn()
Return the ResultColumn that is the source of this VirtualColumnNode.(package private) ResultColumn
getSourceResultColumn()
Return the ResultColumn that is the source of this VirtualColumnNode.(package private) ResultSetNode
getSourceResultSet()
Return the ResultSetNode that is the source of this VirtualColumnNode.(package private) java.lang.String
getTableName()
Get the name of the table the ResultColumn is in, if any.DataTypeDescriptor
getTypeServices()
Get the DataTypeServices from this Node.(package private) boolean
isCloneable()
Return whether or not this expression tree is cloneable.(package private) boolean
isEquivalent(ValueNode o)
Tests if this node is equivalent to the specified ValueNode.(package private) void
printSubNodes(int depth)
Prints the sub-nodes of this object.(package private) void
setCorrelated()
Mark this VCN as a reference to a correlated column.void
setType(DataTypeDescriptor dtd)
Set the DataTypeServices for this ValueNode.boolean
updatableByCursor()
Return whether or not the ResultColumn is wirtable by a positioned update.-
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, bindExpression, categorize, changeToCNF, checkIsBoolean, checkTopPredicatesForEqualsConditions, constantExpression, copyFields, eliminateNots, evaluateConstantExpressions, genEqualsFalseTree, generate, genIsNullTree, genSQLJavaSQLTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isConstantExpression, isInListProbeNode, isParameterNode, isRelationalOperator, isSameNodeKind, optimizableEqualityNode, preprocess, putAndsOnTop, remapColumnReferencesToExpressions, requiresTypeFromContext, selectivity, setCollationInfo, setCollationInfo, setCollationUsingCompilationSchema, setCollationUsingCompilationSchema, setNullability, setTransformed, setType, setType, toString, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, acceptChildren, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
sourceResultSet
private ResultSetNode sourceResultSet
-
sourceColumn
private ResultColumn sourceColumn
-
columnId
int columnId
-
correlated
private boolean correlated
-
-
Constructor Detail
-
VirtualColumnNode
VirtualColumnNode(ResultSetNode sourceResultSet, ResultColumn sourceColumn, int columnId, ContextManager cm) throws StandardException
Constructor for a VirtualColumnNode.- Parameters:
sourceResultSet
- The ResultSetNode where the value is originatingsourceColumn
- The ResultColumn where the value is originatingcolumnId
- The columnId within the current Rowcm
- The context manager- Throws:
StandardException
-
-
Method Detail
-
printSubNodes
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 classQueryTreeNode
- Parameters:
depth
- The depth of this node in the tree
-
getSourceResultSet
ResultSetNode getSourceResultSet()
Return the ResultSetNode that is the source of this VirtualColumnNode.- Returns:
- ResultSetNode
-
getSourceColumn
ResultColumn getSourceColumn()
Return the ResultColumn that is the source of this VirtualColumnNode.- Returns:
- ResultSetNode
-
getTableName
java.lang.String 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- Overrides:
getTableName
in classValueNode
- 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.
-
getSchemaName
java.lang.String getSchemaName() throws StandardException
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- Overrides:
getSchemaName
in classValueNode
- 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.
- Throws:
StandardException
-
updatableByCursor
public boolean updatableByCursor()
Return whether or not the ResultColumn is wirtable by a positioned update.- Overrides:
updatableByCursor
in classValueNode
- Returns:
- TRUE, if the column is a base column of a table and is writable by a positioned update.
-
getSourceResultColumn
ResultColumn getSourceResultColumn()
Return the ResultColumn that is the source of this VirtualColumnNode.- Overrides:
getSourceResultColumn
in classValueNode
- Returns:
- ResultSetNode
-
setCorrelated
void setCorrelated()
Mark this VCN as a reference to a correlated column. (It's source resultSet is an outer ResultSet.
-
getCorrelated
boolean getCorrelated()
Return whether or not this VCN is a correlated reference.- Returns:
- Whether or not this VCN is a correlated reference.
-
isCloneable
boolean isCloneable()
Return whether or not this expression tree is cloneable.- Overrides:
isCloneable
in classValueNode
- Returns:
- boolean Whether or not this expression tree is cloneable.
-
generateExpression
void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
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.- Overrides:
generateExpression
in classValueNode
- Parameters:
acb
- The ExpressionClassBuilder for the class being builtmb
- The method the expression will go into- Throws:
StandardException
- Thrown on error
-
getOrderableVariantType
protected int getOrderableVariantType() throws StandardException
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)- Overrides:
getOrderableVariantType
in classValueNode
- Returns:
- The variant type for the underlying expression.
- Throws:
StandardException
- thrown on error
-
getTypeServices
public final DataTypeDescriptor getTypeServices()
Get the DataTypeServices from this Node.- Overrides:
getTypeServices
in classValueNode
- Returns:
- The DataTypeServices from this Node. This may be null if the node isn't bound yet.
-
setType
public final void setType(DataTypeDescriptor dtd) throws StandardException
Description copied from class:ValueNode
Set the DataTypeServices for this ValueNode. This method is overridden in ParameterNode.- Overrides:
setType
in classValueNode
- Parameters:
dtd
- The DataTypeServices to set in this ValueNode- Throws:
StandardException
-
isEquivalent
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:
- 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.
- Specified by:
isEquivalent
in classValueNode
- Parameters:
o
- the node to compare this ValueNode against.- Returns:
true
if the two nodes are equivalent,false
otherwise.- Throws:
StandardException
-
-