db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1575866 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/GroupByList.java testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
Date Mon, 10 Mar 2014 08:09:07 GMT
Author: kahatlen
Date: Mon Mar 10 08:09:06 2014
New Revision: 1575866

URL: http://svn.apache.org/r1575866
Log:
DERBY-5313: Assert failure with CASE expression in GROUP BY clause

Remove assert that doesn't expect expressions in the GROUP BY list.

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java?rev=1575866&r1=1575865&r2=1575866&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java Mon
Mar 10 08:09:06 2014
@@ -254,24 +254,11 @@ class GroupByList extends OrderedColumnL
 	 */
     void remapColumnReferencesToExpressions() throws StandardException
 	{
-		/* This method is called when flattening a FromTable.  We should
-		 * not be flattening a FromTable if the underlying expression that
-		 * will get returned out, after chopping out the redundant ResultColumns,
-		 * is not a ColumnReference.  (See ASSERT below.)
-		 */
+        /* This method is called when flattening a FromTable. */
         for (GroupByColumn gbc : this)
 		{
-            ValueNode retVN =
-                gbc.getColumnExpression().remapColumnReferencesToExpressions();
-
-			if (SanityManager.DEBUG)
-			{
-				SanityManager.ASSERT(retVN instanceof ColumnReference,
-					"retVN expected to be instanceof ColumnReference, not " +
-					retVN.getClass().getName());
-			}
-
-			gbc.setColumnExpression(retVN);
+            gbc.setColumnExpression(
+                gbc.getColumnExpression().remapColumnReferencesToExpressions());
 		}
 	}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java?rev=1575866&r1=1575865&r2=1575866&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
Mon Mar 10 08:09:06 2014
@@ -2877,4 +2877,29 @@ public class GroupByTest extends BaseJDB
 
             rollback();
     }
+
+    /**
+     * GROUP BY on an expression in a JOIN used to trigger an assert failure.
+     * See DERBY-5313.
+     */
+    public void testDerby5313() throws SQLException {
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+        s.execute("create table d5313_1(a int, b int)");
+        s.execute("create table d5313_2(b int, c int)");
+        s.execute("insert into d5313_1 values (3, 1), (2, 2), (3, 3)");
+        s.execute("insert into d5313_2 values (0, 1), (1, 2), (2, 3), (3, 4)");
+
+        JDBC.assertUnorderedResultSet(
+                s.executeQuery("select a+b, sum(c) from "
+                             + "d5313_1 natural join d5313_2 group by a+b"),
+                new String[][] { { "4", "5" }, { "6", "4" } });
+
+        JDBC.assertUnorderedResultSet(
+                s.executeQuery("select case when a=2 then 1 else 2 end, sum(c) "
+                             + "from d5313_1 natural join d5313_2 group by "
+                             + "case when a=2 then 1 else 2 end"),
+                new String[][] { { "1", "3" }, { "2", "6" } });
+    }
 }



Mime
View raw message