You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2010/03/29 10:56:00 UTC
svn commit: r928649 - in
/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile:
BinaryListOperatorNode.java CoalesceFunctionNode.java ConditionalNode.java
ValueNodeList.java
Author: kahatlen
Date: Mon Mar 29 08:56:00 2010
New Revision: 928649
URL: http://svn.apache.org/viewvc?rev=928649&view=rev
Log:
DERBY-4600: Use ValueNodeList helper methods in CoalesceFunctionNode
Use the helper methods defined in ValueNodeList to process the
argumentsList field in CoalesceFunctionNode. Also add a new helper
method, isEquivalent(), and use it in BinaryListOperatorNode,
ConditionalNode and CoalesceFunctionNode.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java?rev=928649&r1=928648&r2=928649&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java Mon Mar 29 08:56:00 2010
@@ -412,20 +412,12 @@ public abstract class BinaryListOperator
{
return false;
}
-
- int sz = getRightOperandList().size();
- if (sz != other.rightOperandList.size())
- {
- return false;
- }
- for (int i = 0; i < sz; i++)
- {
- ValueNode e = (ValueNode)rightOperandList.elementAt(i);
- if (!e.isEquivalent((ValueNode)other.rightOperandList.elementAt(i)))
- {
- return false;
- }
- }
+
+ if (!rightOperandList.isEquivalent(other.rightOperandList))
+ {
+ return false;
+ }
+
return true;
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java?rev=928649&r1=928648&r2=928649&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java Mon Mar 29 08:56:00 2010
@@ -360,22 +360,12 @@ public class CoalesceFunctionNode extend
}
CoalesceFunctionNode other = (CoalesceFunctionNode)o;
- if (other.argumentsList.size() != argumentsList.size())
+
+ if (!argumentsList.isEquivalent(other.argumentsList))
{
return false;
-
- }
-
- int size = argumentsList.size();
- for (int index = 0; index < size; index++)
- {
- ValueNode v1 = (ValueNode)argumentsList.elementAt(index);
- ValueNode v2 = (ValueNode)other.argumentsList.elementAt(index);
- if (!v1.isEquivalent(v2))
- {
- return false;
- }
}
+
return true;
}
@@ -389,12 +379,7 @@ public class CoalesceFunctionNode extend
{
super.acceptChildren(v);
- int size = argumentsList.size();
- for (int index = 0; index < size; index++)
- {
- argumentsList.setElementAt(
- (QueryTreeNode)(argumentsList.elementAt(index)).accept(v), index);
- }
+ argumentsList = (ValueNodeList) argumentsList.accept(v);
}
/**
@@ -429,14 +414,12 @@ public class CoalesceFunctionNode extend
PredicateList outerPredicateList)
throws StandardException
{
- int argumentsListSize = argumentsList.size();
- for (int i=0; i < argumentsListSize; i++) {
- ((ValueNode)argumentsList.elementAt(i)).preprocess
- (numTables,
- outerFromList,
- outerSubqueryList,
- outerPredicateList);
- }
+ argumentsList.preprocess(
+ numTables,
+ outerFromList,
+ outerSubqueryList,
+ outerPredicateList);
+
return this;
}
@@ -450,10 +433,7 @@ public class CoalesceFunctionNode extend
public ValueNode remapColumnReferencesToExpressions()
throws StandardException
{
- for (int i = 0; i < argumentsList.size(); i++) {
- ValueNode vn = (ValueNode) argumentsList.elementAt(i);
- vn.remapColumnReferencesToExpressions();
- }
+ argumentsList = argumentsList.remapColumnReferencesToExpressions();
return this;
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java?rev=928649&r1=928648&r2=928649&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java Mon Mar 29 08:56:00 2010
@@ -755,22 +755,8 @@ public class ConditionalNode extends Val
if (isSameNodeType(o))
{
ConditionalNode other = (ConditionalNode)o;
- if (thenElseList.size() == other.thenElseList.size()
- && (testCondition.isEquivalent(other.testCondition)))
- {
- int sz = thenElseList.size();
- for (int i = 0; i < sz; i++)
- {
- ValueNode v1 = (ValueNode)thenElseList.elementAt(i);
- ValueNode v2 = (ValueNode)other.thenElseList.elementAt(i);
- if (!v1.isEquivalent(v2))
- {
- return false;
- }
-
- }
- return true;
- }
+ return testCondition.isEquivalent(other.testCondition) &&
+ thenElseList.isEquivalent(other.thenElseList);
}
return false;
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java?rev=928649&r1=928648&r2=928649&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java Mon Mar 29 08:56:00 2010
@@ -583,6 +583,34 @@ public class ValueNodeList extends Query
return this;
}
+ /**
+ * 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.
+ *
+ * @param other the other list
+ * @return {@code true} if the two lists contain equivalent elements, or
+ * {@code false} otherwise
+ * @throws StandardException thrown on error
+ * @see ValueNode#isEquivalent(ValueNode)
+ */
+ boolean isEquivalent(ValueNodeList other) throws StandardException {
+ if (size() != other.size()) {
+ return false;
+ }
+
+ for (int i = 0; i < size(); i++) {
+ ValueNode vn1 = (ValueNode) elementAt(i);
+ ValueNode vn2 = (ValueNode) other.elementAt(i);
+ if (!vn1.isEquivalent(vn2)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/**
* Return whether or not this expression tree represents a constant expression.
*