db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1575226 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 07 Mar 2014 10:34:25 GMT
Author: kahatlen
Date: Fri Mar  7 10:34:25 2014
New Revision: 1575226

URL: http://svn.apache.org/r1575226
Log:
DERBY-4403: Disallow subqueries in the GROUP BY list

Queries that were grouped by subqueries used to fail with a
NullPointerException or an assert failure. Make them fail with a
proper syntax error instead.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.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=1575226&r1=1575225&r2=1575226&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 Fri
Mar  7 10:34:25 2014
@@ -213,11 +213,10 @@ class GroupByList extends OrderedColumnL
 		}
 
 		/* Verify that no subqueries got added to the dummy list */
-		if (SanityManager.DEBUG)
-		{
-			SanityManager.ASSERT(dummySubqueryList.size() == 0,
-				"dummySubqueryList.size() is expected to be 0");
-		}
+        if (dummySubqueryList.size() != 0) {
+            throw StandardException.newException(
+                    SQLState.LANG_SUBQUERY_IN_GROUPBY_LIST);
+        }
 
 		numGroupingColsAdded+= numColsAddedHere;
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1575226&r1=1575225&r2=1575226&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Fri Mar  7 10:34:25
2014
@@ -2432,11 +2432,16 @@ Guide.
             </msg>
 
             <msg>
-                <name>42Y26</name>
+                <name>42Y26.S.0</name>
                 <text>Aggregates are not allowed in the GROUP BY list.</text>
             </msg>
 
             <msg>
+                <name>42Y26.S.1</name>
+                <text>Subqueries are not allowed in the GROUP BY list.</text>
+            </msg>
+
+            <msg>
                 <name>42Y27</name>
                 <text>Parameters are not allowed in the trigger action.</text>
             </msg>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1575226&r1=1575225&r2=1575226&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Fri Mar  7 10:34:25 2014
@@ -982,7 +982,8 @@ public interface SQLState {
 	String LANG_BAD_J_D_B_C_TYPE_INFO                                  = "42Y23";
 	String LANG_VIEW_NOT_UPDATEABLE                                    = "42Y24";
 	String LANG_UPDATE_SYSTEM_TABLE_ATTEMPTED                          = "42Y25";
-    	String LANG_AGGREGATE_IN_GROUPBY_LIST                              = "42Y26";
+    String LANG_AGGREGATE_IN_GROUPBY_LIST                              = "42Y26.S.0";
+    String LANG_SUBQUERY_IN_GROUPBY_LIST                               = "42Y26.S.1";
 	String LANG_NO_PARAMS_IN_TRIGGER_ACTION                            = "42Y27";
 	// String LANG_NO_TRIGGER_ON_SYSTEM_TABLE                             = "42Y28"; -- replaced
by 42X62
 	String LANG_INVALID_NON_GROUPED_SELECT_LIST                        = "42Y29";

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=1575226&r1=1575225&r2=1575226&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
Fri Mar  7 10:34:25 2014
@@ -370,7 +370,13 @@ public class GroupByTest extends BaseJDB
         
         assertStatementError("X0X67", st,
             " select c1, max(1) from unmapped group by c1");
-		st.close();
+
+        // group by on aggregate
+        assertCompileError("42Y26", "select sum(a) from t1 group by sum(a)");
+
+        // group by on subquery (DERBY-4403)
+        assertCompileError("42Y26",
+                "select sum(a) from t1 group by (select a from t1)");
 	}
 
 	/**



Mime
View raw message