db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r431593 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java testing/org/apache/derbyTesting/functionTests/master/subquery.out testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
Date Tue, 15 Aug 2006 12:46:31 GMT
Author: kahatlen
Date: Tue Aug 15 05:46:30 2006
New Revision: 431593

URL: http://svn.apache.org/viewvc?rev=431593&view=rev
Log:
DERBY-1574: NullPointerException in UPDATE with COALESCE and subquery

This patch
- adds a preprocess method to CoalesceFunctionNode to override the one
  in ValueNode, thus making sure the arguments get handled.
- adds a printSubNodes method to CoalesceFunctionNode (was missing
  too, I discovered, when I was trying to look at the parse tree after
  binding).
- adds a new test case to coalesceTests.java and an updated master

Patch contributed by Dag H. Wanvik.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql

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=431593&r1=431592&r2=431593&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
Tue Aug 15 05:46:30 2006
@@ -317,4 +317,57 @@
 		}
 	}
 
+	/**
+	 * Preprocess an expression tree.  We do a number of transformations
+	 * here (including subqueries, IN lists, LIKE and BETWEEN) plus
+	 * subquery flattening.
+	 * NOTE: This is done before the outer ResultSetNode is preprocessed.
+	 *
+	 * @param	numTables			Number of tables in the DML Statement
+	 * @param	outerFromList		FromList from outer query block
+	 * @param	outerSubqueryList	SubqueryList from outer query block
+	 * @param	outerPredicateList	PredicateList from outer query block
+	 *
+	 * @return						The modified expression
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public ValueNode preprocess(int numTables,
+								FromList outerFromList,
+								SubqueryList outerSubqueryList,
+								PredicateList outerPredicateList) 
+					throws StandardException
+	{
+		int argumentsListSize = argumentsList.size();
+		for (int i=0; i < argumentsListSize; i++) {
+			((ValueNode)argumentsList.elementAt(i)).preprocess
+				(numTables,
+				 outerFromList,
+				 outerSubqueryList,
+				 outerPredicateList);
+		}
+		return this;
+	}
+
+
+	/**
+	 * Prints the sub-nodes of this object.  See QueryTreeNode.java for
+	 * how tree printing is supposed to work.
+	 *
+	 * @param depth					The depth of this node in the tree
+	 */
+
+	public void printSubNodes(int depth)
+	{
+		if (SanityManager.DEBUG)
+		{
+			super.printSubNodes(depth);
+			printLabel(depth, "argumentsList: ");
+			int argumentsListSize = argumentsList.size();
+			for (int i=0; i < argumentsListSize; i++) {
+			    ((ValueNode)argumentsList.elementAt(i)).treePrint(depth+1);
+			}
+		}
+	}
+        
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out?rev=431593&r1=431592&r2=431593&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
Tue Aug 15 05:46:30 2006
@@ -1645,4 +1645,28 @@
 0 rows inserted/updated/deleted
 ij> drop table t4;
 0 rows inserted/updated/deleted
+ij> -- DERBY-1574: Subquery in COALESCE gives NPE due
+-- to preprocess not implemented for that node type
+create table t1 (id int);
+0 rows inserted/updated/deleted
+ij> create table t2 (i integer primary key, j int);
+0 rows inserted/updated/deleted
+ij> insert into t1 values 1,2,3,4,5;
+5 rows inserted/updated/deleted
+ij> insert into t2 values (1,1),(2,4),(3,9),(4,16);
+4 rows inserted/updated/deleted
+ij> update t1 set id = coalesce((select j from t2 where t2.i=t1.id), 0);
+5 rows inserted/updated/deleted
+ij> select * from t1;
+ID         
+-----------
+1          
+4          
+9          
+16         
+0          
+ij> drop table t1;
+0 rows inserted/updated/deleted
+ij> drop table t2;
+0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql?rev=431593&r1=431592&r2=431593&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
Tue Aug 15 05:46:30 2006
@@ -525,3 +525,18 @@
 drop table t2;
 drop table t3;
 drop table t4;
+
+-- DERBY-1574: Subquery in COALESCE gives NPE due
+-- to preprocess not implemented for that node type
+create table t1 (id int);
+create table t2 (i integer primary key, j int);
+
+insert into t1 values 1,2,3,4,5;
+insert into t2 values (1,1),(2,4),(3,9),(4,16);
+ 
+update t1 set id = coalesce((select j from t2 where t2.i=t1.id), 0);
+select * from t1;
+
+drop table t1;
+drop table t2;
+



Mime
View raw message