org.apache.derby.impl.sql.compile
Class ValueNodeList

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.QueryTreeNodeVector
          extended by org.apache.derby.impl.sql.compile.ValueNodeList
All Implemented Interfaces:
Visitable

public class ValueNodeList
extends QueryTreeNodeVector

A ValueNodeList represents a list of ValueNodes within a specific predicate (eg, IN list, NOT IN list or BETWEEN) in a DML statement. It extends QueryTreeNodeVector.


Field Summary
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
ValueNodeList()
           
 
Method Summary
 void addValueNode(ValueNode valueNode)
          Add a ValueNode to the list.
(package private)  boolean allSamePrecendence(int precedence)
          Return whether or not all of the entries in the list have the same type precendence as the specified value.
 void bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
 boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)
          Categorize this predicate.
 void comparable(ValueNode leftOperand)
          Determine whether or not the leftOperand is comparable() with all of the elements in the list.
 void compatible(ValueNode leftOperand)
          Make sure that passed ValueNode's type is compatible with the non-parameter elements in the ValueNodeList.
 boolean constantExpression(PredicateList whereClause)
           
 boolean containsAllConstantNodes()
          Does this list contain all ConstantNodes?
 boolean containsAllParameterNodes()
          Does this list contain all ParameterNodes?
 boolean containsOnlyConstantAndParamNodes()
          Does this list *only* contain constant and/or parameter nodes?
 boolean containsParameterNode()
          Does this list contain a ParameterNode?
 void genSQLJavaSQLTrees()
          Generate a SQL->Java->SQL conversion tree any node in the list which is not a system built-in type.
 DataTypeDescriptor getDominantTypeServices()
          Get the dominant DataTypeServices from the elements in the list.
protected  int getOrderableVariantType()
          Return the variant type for the underlying expression.
 DataTypeDescriptor getTypeServices()
          Get the first non-null DataTypeServices from the elements in the list.
 boolean isConstantExpression()
          Return whether or not this expression tree represents a constant expression.
(package private)  boolean isEquivalent(ValueNodeList other)
          Check if all the elements in this list are equivalent to the elements in another list.
 boolean isNullable()
          Determine whether or not any of the elements in the list are nullable.
 void preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
          Preprocess a ValueNodeList.
 ValueNodeList remapColumnReferencesToExpressions()
          Remap all ColumnReferences in this tree to be clones of the underlying expression.
 void setParameterDescriptor(DataTypeDescriptor descriptor)
          Set the descriptor for every ParameterNode in the list.
(package private)  void sortInAscendingOrder(DataValueDescriptor judgeODV)
          Sort the entries in the list in ascending order.
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
acceptChildren, addElement, destructiveAppend, elementAt, indexOf, insertElementAt, nondestructiveAppend, printSubNodes, remove, removeAllElements, removeElement, removeElementAt, setElementAt, size
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, toString, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValueNodeList

public ValueNodeList()
Method Detail

addValueNode

public void addValueNode(ValueNode valueNode)
                  throws StandardException
Add a ValueNode to the list.

Parameters:
valueNode - A ValueNode to add to the list
Throws:
StandardException - Thrown on error

bindExpression

public void bindExpression(FromList fromList,
                           SubqueryList subqueryList,
                           java.util.Vector aggregateVector)
                    throws StandardException
Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.

Parameters:
fromList - The FROM list for the query this expression is in, for binding columns.
subqueryList - The subquery list being built as we find SubqueryNodes
aggregateVector - The aggregate vector being built as we find AggregateNodes
Throws:
StandardException - Thrown on error

genSQLJavaSQLTrees

public void genSQLJavaSQLTrees()
                        throws StandardException
Generate a SQL->Java->SQL conversion tree any node in the list which is not a system built-in type. This is useful when doing comparisons, built-in functions, etc. on java types which have a direct mapping to system built-in types.

Throws:
StandardException - Thrown on error

getDominantTypeServices

public DataTypeDescriptor getDominantTypeServices()
                                           throws StandardException
Get the dominant DataTypeServices from the elements in the list. This method will also set the correct collation information on the dominant DataTypeService if we are dealing with character string datatypes. Algorithm for determining collation information This method will check if it is dealing with character string datatypes. If yes, then it will check if all the character string datatypes have the same collation derivation and collation type associated with them. If not, then the resultant DTD from this method will have collation derivation of NONE. If yes, then the resultant DTD from this method will have the same collation derivation and collation type as all the character string datatypes. Note that this method calls DTD.getDominantType and that method returns the dominant type of the 2 DTDs involved in this method. That method sets the collation info on the dominant type following the algorithm mentioned in the comments of

Returns:
DataTypeServices The dominant DataTypeServices.
Throws:
StandardException - Thrown on error
See Also:
With that algorithm, if one DTD has collation derivation of NONE and the other DTD has collation derivation of IMPLICIT, then the return DTD from DTD.getDominantType will have collation derivation of IMPLICIT. That is not the correct algorithm for aggregate operators. SQL standards says that if EVERY type has implicit derivation AND is of the same type, then the collation of the resultant will be of that type with derivation IMPLICIT. To provide this behavior for aggregate operator, we basically ignore the collation type and derivation picked by DataTypeDescriptor.getDominantType. Instead we let getDominantTypeServices use the simple algorithm listed at the top of this method's comments to determine the collation type and derivation for this ValueNodeList object.

getTypeServices

public DataTypeDescriptor getTypeServices()
                                   throws StandardException
Get the first non-null DataTypeServices from the elements in the list.

Returns:
DataTypeServices The first non-null DataTypeServices.
Throws:
StandardException - Thrown on error

allSamePrecendence

boolean allSamePrecendence(int precedence)
                     throws StandardException
Return whether or not all of the entries in the list have the same type precendence as the specified value.

Parameters:
precedence - The specified precedence.
Returns:
Whether or not all of the entries in the list have the same type precendence as the specified value.
Throws:
StandardException

compatible

public void compatible(ValueNode leftOperand)
                throws StandardException
Make sure that passed ValueNode's type is compatible with the non-parameter elements in the ValueNodeList.

Parameters:
leftOperand - Check for compatibility against this parameter's type
Throws:
StandardException

comparable

public void comparable(ValueNode leftOperand)
                throws StandardException
Determine whether or not the leftOperand is comparable() with all of the elements in the list. Throw an exception if any of them are not comparable.

Parameters:
leftOperand - The left side of the expression
Throws:
StandardException - Thrown on error

isNullable

public boolean isNullable()
                   throws StandardException
Determine whether or not any of the elements in the list are nullable.

Returns:
boolean Whether or not any of the elements in the list are nullable.
Throws:
StandardException

containsParameterNode

public boolean containsParameterNode()
Does this list contain a ParameterNode?

Returns:
boolean Whether or not the list contains a ParameterNode

containsAllParameterNodes

public boolean containsAllParameterNodes()
Does this list contain all ParameterNodes?

Returns:
boolean Whether or not the list contains all ParameterNodes

containsAllConstantNodes

public boolean containsAllConstantNodes()
Does this list contain all ConstantNodes?

Returns:
boolean Whether or not the list contains all ConstantNodes

containsOnlyConstantAndParamNodes

public boolean containsOnlyConstantAndParamNodes()
Does this list *only* contain constant and/or parameter nodes?

Returns:
boolean True if every node in this list is either a constant node or parameter node.

sortInAscendingOrder

void sortInAscendingOrder(DataValueDescriptor judgeODV)
                    throws StandardException
Sort the entries in the list in ascending order. (All values are assumed to be constants.)

Parameters:
judgeODV - In case of type not exactly matching, the judging type.
Throws:
StandardException - Thrown on error

setParameterDescriptor

public void setParameterDescriptor(DataTypeDescriptor descriptor)
                            throws StandardException
Set the descriptor for every ParameterNode in the list.

Parameters:
descriptor - The DataTypeServices to set for the parameters
Throws:
StandardException - Thrown on error

preprocess

public void preprocess(int numTables,
                       FromList outerFromList,
                       SubqueryList outerSubqueryList,
                       PredicateList outerPredicateList)
                throws StandardException
Preprocess a ValueNodeList. For now, we just preprocess each ValueNode in the list.

Parameters:
numTables - Number of tables in the DML Statement
outerFromList - FromList from outer query block
outerSubqueryList - SubqueryList from outer query block
outerPredicateList - PredicateList from outer query block
Throws:
StandardException - Thrown on error

remapColumnReferencesToExpressions

public ValueNodeList remapColumnReferencesToExpressions()
                                                 throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.

Returns:
ValueNodeList The remapped expression tree.
Throws:
StandardException - Thrown on error

isEquivalent

boolean isEquivalent(ValueNodeList other)
               throws StandardException
Check if all the elements in this list are equivalent to the elements in another list. The two lists must have the same size, and the equivalent nodes must appear in the same order in both lists, for the two lists to be equivalent.

Parameters:
other - the other list
Returns:
true if the two lists contain equivalent elements, or false otherwise
Throws:
StandardException - thrown on error
See Also:
ValueNode.isEquivalent(ValueNode)

isConstantExpression

public boolean isConstantExpression()
Return whether or not this expression tree represents a constant expression.

Returns:
Whether or not this expression tree represents a constant expression.

constantExpression

public boolean constantExpression(PredicateList whereClause)
See Also:
ValueNode.constantExpression(org.apache.derby.impl.sql.compile.PredicateList)

categorize

public boolean categorize(JBitSet referencedTabs,
                          boolean simplePredsOnly)
                   throws StandardException
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. RESOLVE - revisit this issue once we have views.

Parameters:
referencedTabs - JBitSet with bit map of referenced FromTables
simplePredsOnly - Whether or not to consider method calls, field references and conditional nodes when building bit map
Returns:
boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.
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 - constant

Returns:
The variant type for the underlying expression.
Throws:
StandardException - thrown on error

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.