|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> sql >> [ compile overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.impl.sql.compile
Class ColumnReference

java.lang.Objectorg.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.ValueNode
org.apache.derby.impl.sql.compile.ColumnReference
- All Implemented Interfaces:
- org.apache.derby.iapi.sql.compile.Visitable
- public class ColumnReference
- extends ValueNode
A ColumnReference represents a column in the query tree. The parser generates a ColumnReference for each column reference. A column refercence 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.
| Field Summary | |
java.lang.String |
columnName
|
int |
columnNumber
|
private int |
nestingLevel
|
(package private) int |
origColumnNumber
|
java.lang.String |
origName
|
(package private) ResultColumn |
origSource
|
(package private) int |
origTableNumber
|
private boolean |
replacesAggregate
|
ResultColumn |
source
|
private int |
sourceLevel
|
TableName |
tableName
|
int |
tableNumber
|
private int |
tokBeginOffset
|
private int |
tokEndOffset
|
| Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode |
clause, dataTypeServices, IN_HAVING_CLAUSE, IN_SELECT_LIST, IN_UNKNOWN_CLAUSE, IN_WHERE_CLAUSE, transformed |
| Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode |
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset |
| Constructor Summary | |
ColumnReference()
|
|
| Method Summary | |
ValueNode |
bindExpression(FromList fromList,
SubqueryList subqueryList,
java.util.Vector aggregateVector)
Bind this expression. |
boolean |
categorize(org.apache.derby.iapi.util.JBitSet referencedTabs,
boolean simplePredsOnly)
Categorize this predicate. |
boolean |
constantExpression(PredicateList whereClause)
Return whether or not this expression tree represents a constant value. |
void |
copyFields(ColumnReference oldCR)
Copy all of the "appropriate fields" for a shallow copy. |
void |
generateExpression(ExpressionClassBuilder acb,
org.apache.derby.iapi.services.compiler.MethodBuilder mb)
ColumnReference's are to the current row in the system. |
ValueNode |
getClone()
Return a clone of this node. |
java.lang.String |
getColumnName()
Get the name of this column |
int |
getColumnNumber()
Get the column number for this ColumnReference. |
(package private) boolean |
getCorrelated()
Return whether or not this CR is correlated. |
boolean |
getGeneratedToReplaceAggregate()
Determine whether or not this node was generated to replace an aggregate in the user's SELECT. |
(package private) int |
getNestingLevel()
Get the nesting level for this CR. |
protected int |
getOrderableVariantType()
Return the variant type for the underlying expression. |
java.lang.String |
getSchemaName()
Get the user-supplied schema name of this column. |
ResultColumn |
getSource()
Get the source this columnReference |
(package private) int |
getSourceLevel()
Get the source level for this CR. |
ResultColumn |
getSourceResultColumn()
Get the source for this ValueNode. |
java.lang.String |
getSourceSchemaName()
Get the name of the schema for the Column's base table, if any. |
java.lang.String |
getSourceTableName()
Get the name of the underlying(base) table this column comes from, if any. |
java.lang.String |
getSQLColumnName()
Get the column name for purposes of error messages or debugging. |
java.lang.String |
getTableName()
Get the user-supplied table name of this column. |
TableName |
getTableNameNode()
Return the table name as the node it is. |
int |
getTableNumber()
Get the table number for this ColumnReference. |
(package private) void |
getTablesReferenced(org.apache.derby.iapi.util.JBitSet refs)
Update the table map to reflect the source of this CR. |
int |
getTokenBeginOffset()
Get the begin offset of the parser token for the column name Will only be set when the CR was generated by the parser. |
int |
getTokenEndOffset()
Get the end offset of the parser token for the column name. |
org.apache.derby.iapi.types.DataTypeDescriptor |
getTypeServices()
Get the DataTypeServices from this Node. |
void |
init(java.lang.Object columnName,
java.lang.Object tableName)
Initializer. |
void |
init(java.lang.Object columnName,
java.lang.Object tableName,
java.lang.Object tokBeginOffset,
java.lang.Object tokEndOffset)
Initializer. |
boolean |
isCloneable()
Return whether or not this expression tree is cloneable. |
void |
markGeneratedToReplaceAggregate()
Mark this node as being generated to replace an aggregate. |
(package private) boolean |
pointsToColumnReference()
Return whether or not the source of this ColumnReference is itself a ColumnReference. |
void |
printSubNodes(int depth)
Prints the sub-nodes of this object. |
ValueNode |
putAndsOnTop()
Do the 1st step in putting an expression into conjunctive normal form. |
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. |
ValueNode |
remapColumnReferencesToExpressions()
Remap all ColumnReferences in this tree to be clones of the underlying expression. |
void |
setColumnName(java.lang.String columnName)
Set the name of this column |
(package private) void |
setNestingLevel(int nestingLevel)
Set the nesting level for this CR. |
void |
setSource(ResultColumn source)
Set the source this columnReference |
(package private) void |
setSourceLevel(int sourceLevel)
Set the source level for this CR. |
void |
setTableNameNode(TableName tableName)
|
void |
setTableNumber(int tableNumber)
Set this ColumnReference to refer to the given table number. |
java.lang.String |
toString()
Convert this object to a String. |
void |
unRemapColumnReferences()
|
boolean |
updatableByCursor()
Is the column wirtable by the cursor or not. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
columnName
public java.lang.String columnName
tableName
public TableName tableName
tableNumber
public int tableNumber
columnNumber
public int columnNumber
source
public ResultColumn source
origSource
ResultColumn origSource
origName
public java.lang.String origName
origTableNumber
int origTableNumber
origColumnNumber
int origColumnNumber
replacesAggregate
private boolean replacesAggregate
nestingLevel
private int nestingLevel
sourceLevel
private int sourceLevel
tokBeginOffset
private int tokBeginOffset
tokEndOffset
private int tokEndOffset
| Constructor Detail |
ColumnReference
public ColumnReference()
| Method Detail |
init
public void init(java.lang.Object columnName, java.lang.Object tableName, java.lang.Object tokBeginOffset, java.lang.Object tokEndOffset)
- Initializer.
This one is called by the parser where we could
be dealing with delimited identifiers.
- Overrides:
initin classQueryTreeNode
init
public void init(java.lang.Object columnName, java.lang.Object tableName)
- Initializer.
- Overrides:
initin classQueryTreeNode
toString
public java.lang.String toString()
- Convert this object to a String. See comments in QueryTreeNode.java
for how this should be done for tree printing.
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:
printSubNodesin classQueryTreeNode
getTokenBeginOffset
public int getTokenBeginOffset()
- Get the begin offset of the parser token for the column name
Will only be set when the CR was generated by the
parser.
getTokenEndOffset
public int getTokenEndOffset()
- Get the end offset of the parser token for the column name.
Will only be set when the CR was generated by the
parser.
getCorrelated
boolean getCorrelated()
- Return whether or not this CR is correlated.
setNestingLevel
void setNestingLevel(int nestingLevel)
- Set the nesting level for this CR. (The nesting level
at which the CR appears.)
getNestingLevel
int getNestingLevel()
- Get the nesting level for this CR.
setSourceLevel
void setSourceLevel(int sourceLevel)
- Set the source level for this CR. (The nesting level
of the source of the CR.)
getSourceLevel
int getSourceLevel()
- Get the source level for this CR.
markGeneratedToReplaceAggregate
public 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.
getGeneratedToReplaceAggregate
public boolean getGeneratedToReplaceAggregate()
- Determine whether or not this node was generated to
replace an aggregate in the user's SELECT.
getClone
public ValueNode getClone() throws org.apache.derby.iapi.error.StandardException
copyFields
public void copyFields(ColumnReference oldCR) throws org.apache.derby.iapi.error.StandardException
- Copy all of the "appropriate fields" for a shallow copy.
bindExpression
public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector) throws org.apache.derby.iapi.error.StandardException
- 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)
- Overrides:
bindExpressionin classValueNode
getSQLColumnName
public java.lang.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.
getColumnName
public java.lang.String getColumnName()
- Get the name of this column
- Overrides:
getColumnNamein classValueNode
setColumnName
public void setColumnName(java.lang.String columnName)
- Set the name of this column
getTableNumber
public int getTableNumber()
- Get the table number for this ColumnReference.
setTableNumber
public void setTableNumber(int tableNumber)
- Set this ColumnReference to refer to the given table number.
getTableName
public java.lang.String 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
- Overrides:
getTableNamein classValueNode
getSourceTableName
public java.lang.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
getSourceSchemaName
public java.lang.String getSourceSchemaName() throws org.apache.derby.iapi.error.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
updatableByCursor
public boolean updatableByCursor()
- Is the column wirtable by the cursor or not. (ie, is it in the list of FOR UPDATE columns list)
- Overrides:
updatableByCursorin classValueNode
getTableNameNode
public TableName getTableNameNode()
- Return the table name as the node it is.
setTableNameNode
public void setTableNameNode(TableName tableName)
getColumnNumber
public int getColumnNumber()
- Get the column number for this ColumnReference.
getSource
public ResultColumn getSource()
- Get the source this columnReference
setSource
public void setSource(ResultColumn source)
- Set the source this columnReference
putAndsOnTop
public ValueNode putAndsOnTop() throws org.apache.derby.iapi.error.StandardException
- 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.
- Overrides:
putAndsOnTopin classValueNode
categorize
public boolean categorize(org.apache.derby.iapi.util.JBitSet referencedTabs, boolean simplePredsOnly)
- 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.
RESOLVE - revisit this issue once we have views.
- Overrides:
categorizein classValueNode
remapColumnReferences
public 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.
unRemapColumnReferences
public void unRemapColumnReferences()
getSourceResultColumn
public ResultColumn getSourceResultColumn()
- Description copied from class:
ValueNode - Get the source for this ValueNode.
- Overrides:
getSourceResultColumnin classValueNode
remapColumnReferencesToExpressions
public ValueNode remapColumnReferencesToExpressions() throws org.apache.derby.iapi.error.StandardException
- Remap all ColumnReferences in this tree to be clones of the
underlying expression.
- Overrides:
remapColumnReferencesToExpressionsin classValueNode
getTablesReferenced
void getTablesReferenced(org.apache.derby.iapi.util.JBitSet refs)
- Update the table map to reflect the source
of this CR.
isCloneable
public boolean isCloneable()
- Return whether or not this expression tree is cloneable.
- Overrides:
isCloneablein classValueNode
constantExpression
public boolean constantExpression(PredicateList whereClause)
- Description copied from class:
ValueNode - 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.
- Overrides:
constantExpressionin classValueNode
generateExpression
public void generateExpression(ExpressionClassBuilder acb, org.apache.derby.iapi.services.compiler.MethodBuilder mb) throws org.apache.derby.iapi.error.StandardException
- 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.
- Overrides:
generateExpressionin classValueNode
getSchemaName
public java.lang.String 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
- Overrides:
getSchemaNamein classValueNode
getOrderableVariantType
protected int 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)
- Overrides:
getOrderableVariantTypein classValueNode
pointsToColumnReference
boolean pointsToColumnReference()
- Return whether or not the source of this ColumnReference is itself a ColumnReference.
getTypeServices
public org.apache.derby.iapi.types.DataTypeDescriptor getTypeServices()
- Get the DataTypeServices from this Node.
- Overrides:
getTypeServicesin classValueNode
|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> sql >> [ compile overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC