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 2009/09/25 22:57:21 UTC

svn commit: r819006 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java

Author: kahatlen
Date: Fri Sep 25 20:57:20 2009
New Revision: 819006

URL: http://svn.apache.org/viewvc?rev=819006&view=rev
Log:
DERBY-4342: SQLSTATE 38000 (NullPointerException) at inner self join and value(x1, x2...)

Override ValueNode.remapColumnReferencesToExpressions() in CoalesceFunctionNode
so that its arguments are properly remapped. The lack of remapping made the
generated code access the wrong result set, eventually causing the
NullPointerException.

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/tests/lang/CoalesceTest.java

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=819006&r1=819005&r2=819006&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 Fri Sep 25 20:57:20 2009
@@ -427,4 +427,22 @@
 		}
 		return this;
 	}
+
+    /**
+     * Remap all the {@code ColumnReference}s in this tree to be clones of
+     * the underlying expression.
+     *
+     * @return the remapped tree
+     * @throws StandardException if an error occurs
+     */
+    public ValueNode remapColumnReferencesToExpressions()
+            throws StandardException
+    {
+        for (int i = 0; i < argumentsList.size(); i++) {
+            ValueNode vn = (ValueNode) argumentsList.elementAt(i);
+            vn.remapColumnReferencesToExpressions();
+        }
+        return this;
+    }
+
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java?rev=819006&r1=819005&r2=819006&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java Fri Sep 25 20:57:20 2009
@@ -30,10 +30,10 @@
 import java.io.UnsupportedEncodingException;
 
 import junit.framework.Test;
-import junit.framework.TestSuite;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
 
 
 /**
@@ -1170,6 +1170,19 @@
                expectedValues[index++]);
     }
 
+    /**
+     * Regression test for DERBY-4342. A self-join with COALESCE in the WHERE
+     * clause used to fail with a NullPointerException because
+     * CoalesceFunctionNode didn't remap column references correctly.
+     */
+    public void testColumnRemappingDerby4342() throws SQLException {
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+                "select t1.smallintcol from " +
+                "AllDataTypesTable t1 join AllDataTypesTable t2 " +
+                "on t1.smallintcol=t2.smallintcol where " +
+                "coalesce(t1.smallintcol, t1.integercol) = 1"),
+                "1");
+    }
 
     /**************supporting methods *******************/
     private void dumpRS(ResultSet rs, String expectedValue) throws SQLException