db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r881074 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
Date Tue, 17 Nov 2009 00:46:41 GMT
Author: mamta
Date: Tue Nov 17 00:46:40 2009
New Revision: 881074

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

Group by should not allow aggregates in it. We were able to detect "froup by (sum(j))" but
not "group by (4+sum(j))". That's because we were not looking deep enough inside the group
by column.


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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=881074&r1=881073&r2=881074&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Tue Nov
17 00:46:40 2009
@@ -9743,17 +9743,19 @@
 {
 	columnExpression = additiveExpression(null, 0, false)
 	{
+		/* Aggregates not allowed in group by */
+		HasNodeVisitor visitor =
+			new HasNodeVisitor(AggregateNode.class);
+		columnExpression.accept(visitor);
+		if (visitor.hasNode())
+		{
+			{if (true) throw StandardException.newException(
+				SQLState.LANG_AGGREGATE_IN_GROUPBY_LIST);}
+		}
 		if (columnExpression.isParameterNode()) 
 	    	{
 			throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, "?");
 	    	}
-		if (columnExpression instanceof AggregateNode)
-		{
-			AggregateNode agNode = (AggregateNode)columnExpression;
-			throw StandardException.newException(
-				SQLState.LANG_AGGREGATE_IN_GROUPBY_LIST, 
-				agNode.getAggregateName());
-		}        
 		groupingCols.addGroupByColumn(
 			(GroupByColumn) nodeFactory.getNode(
 							C_NodeTypes.GROUP_BY_COLUMN,

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java?rev=881074&r1=881073&r2=881074&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
Tue Nov 17 00:46:40 2009
@@ -123,6 +123,18 @@
     }
     
     /**
+     * DERBY-4202 Aggregates not allowed in group by
+     * @throws Exception
+     */
+    public void testDerby4402AggregateInGroupBy() throws Exception
+    {
+    	assertCompileError(
+                "42Y26", "select c1 from test group by sum(c3)");
+    	assertCompileError(
+                "42Y26", "select c1 from test group by (c1+sum(c3))");
+    }
+    
+    /**
      * queries which combine compound expressions and simple column refs.
      */
     public void testDerby3094Expressions() throws Exception



Mime
View raw message