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 mi...@apache.org on 2014/10/02 19:00:26 UTC
svn commit: r1629018 - in /db/derby/code/branches/10.10: ./
java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
Author: mikem
Date: Thu Oct 2 17:00:26 2014
New Revision: 1629018
URL: http://svn.apache.org/r1629018
Log:
DERBY-5313: Assert failure with CASE expression in GROUP BY clause
backported change #1575866 from trunk to 10.10 branch, had to do hand
merging due to jdk5 code differences in 10.11.
Remove assert that doesn't expect expressions in the GROUP BY list.
Modified:
db/derby/code/branches/10.10/ (props changed)
db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1575866
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java?rev=1629018&r1=1629017&r2=1629018&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java Thu Oct 2 17:00:26 2014
@@ -262,24 +262,14 @@ public class GroupByList extends Ordered
GroupByColumn gbc;
int size = size();
- /* 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 (int index = 0; index < size; index++)
{
ValueNode retVN;
gbc = (GroupByColumn) elementAt(index);
- retVN = gbc.getColumnExpression().remapColumnReferencesToExpressions();
-
- if (SanityManager.DEBUG)
- {
- SanityManager.ASSERT(retVN instanceof ColumnReference,
- "retVN expected to be instanceof ColumnReference, not " +
- retVN.getClass().getName());
- }
+ retVN =
+ gbc.getColumnExpression().remapColumnReferencesToExpressions();
gbc.setColumnExpression(retVN);
}
Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java?rev=1629018&r1=1629017&r2=1629018&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByTest.java Thu Oct 2 17:00:26 2014
@@ -2875,4 +2875,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" } });
+ }
}