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 ma...@apache.org on 2008/10/17 18:12:57 UTC

svn commit: r705660 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java

Author: mamta
Date: Fri Oct 17 09:12:56 2008
New Revision: 705660

URL: http://svn.apache.org/viewvc?rev=705660&view=rev
Log:
DERBY-2872

Merging 705037 from trunk into 10.3 release where this bug was introduced. Copying the commit comments from 705037 here for reference.

The NPE in this jira entry was caused by the missing overwrite of accept() method in IndexToBaseRowNode. 
Because of the missing code, the additional layer of VirtualColumn node over ResultColumn was not 
happening for the where clause in HAVING. Once the accept method was added to IndexToBaseRowNode, the 
VirtualColumn on top of the ResultColumn got the correct resultset number associated with it and at the 
code generation time, we start referencing the correct resultset rather than the one associated with 
the JOIN clause. Thanks a ton to Army and Bryan on this jira entry for their help. 

I have added a test case for this in lang/GroupByTest.java 


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java?rev=705660&r1=705659&r2=705660&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java Fri Oct 17 09:12:56 2008
@@ -27,6 +27,8 @@
 import org.apache.derby.iapi.sql.compile.CostEstimate;
 import org.apache.derby.iapi.sql.compile.Optimizable;
 import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;
+import org.apache.derby.iapi.sql.compile.Visitable;
+import org.apache.derby.iapi.sql.compile.Visitor;
 
 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
 
@@ -409,4 +411,30 @@
 		return indexColMapping;
 	}
 
+	/**
+	 * Accept a visitor, and call v.visit()
+	 * on child nodes as necessary.  
+	 * 
+	 * @param v the visitor
+	 *
+	 * @exception StandardException on error
+	 */
+	public Visitable accept(Visitor v) 
+		throws StandardException
+	{
+		if (v.skipChildren(this))
+		{
+			return v.visit(this);
+		}
+
+		Visitable returnNode = super.accept(v);
+
+		if (source != null && !v.stopTraversal())
+		{
+			source = (FromBaseTable)source.accept(v);
+		}
+
+		return returnNode;
+	}
+
 }

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java?rev=705660&r1=705659&r2=705660&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java Fri Oct 17 09:12:56 2008
@@ -139,6 +139,45 @@
         String [][] expectedRows = {{"A","2"},{"B","2"}};
         JDBC.assertFullResultSet(rs, expectedRows);
         s.executeUpdate("DROP TABLE TAB");
+
+        //Following setup is for DERBY-3872
+        s.executeUpdate(
+        		"CREATE TABLE EMPTAB (EMPID INTEGER NOT NULL, "
+        		+ "SALARY DECIMAL(10, 4), DEPT_DEPTNO INTEGER)"); 
+        s.executeUpdate(
+        		"ALTER TABLE EMPTAB ADD CONSTRAINT " +
+        		"PK_EMPTAB PRIMARY KEY (EMPID)"); 
+        s.executeUpdate(
+        		"CREATE TABLE DEPTTAB (DEPTNO INTEGER NOT NULL)");
+        s.executeUpdate(
+    		  "ALTER TABLE DEPTTAB ADD CONSTRAINT "+
+    		  "PK_DEPTTAB PRIMARY KEY (DEPTNO)");
+        s.executeUpdate(
+    		  "insert into DEPTTAB values( 1 )");
+        s.executeUpdate(
+    		  "insert into EMPTAB values( 1, 1000, 1 )"); 
+
+        //Test case for DERBY-3872 Prior to fix for DERBY-3872, following
+        //query resulted in NPE because of missing chain of
+        //VirtualColumn-to-ResultColumn nodes for the where clause in
+        //the HAVING clause. The reason for this that we didn't overwrite 
+        //the method "accept()" in IndexToBaseRowNode. This missing code
+        //caused Derby to associate the ResultColumn for the HAVING
+        //clause incorrectly with the ResultColumn used for the join
+        //clause. More info can be found in the jira
+        rs = s.executeQuery(
+        		"select  q1.DEPTNO from DEPTTAB q1, EMPTAB q2 where " +
+        		"( integer (1.1) = 1)  and  ( q2.DEPT_DEPTNO = q1.DEPTNO) "+
+        		" GROUP BY q1.DEPTNO HAVING  max( q2.SALARY) >=  "+
+        		"( select  q3.SALARY from EMPTAB q3 where  "+
+        		"(q3.EMPID =  q1.DEPTNO) )");
+        
+        expectedRows = new String [][]
+        {
+            {"1"}
+        };
+        JDBC.assertFullResultSet(rs, expectedRows, true);
+
     }
 
 	public void testDerbyOrderByOnAggregate() throws SQLException