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 km...@apache.org on 2008/05/01 20:58:11 UTC

svn commit: r652622 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/

Author: kmarsden
Date: Thu May  1 11:58:09 2008
New Revision: 652622

URL: http://svn.apache.org/viewvc?rev=652622&view=rev
Log:
DERBY-3649  can't call a stored function with an aggregate argument without getting the following error: ERROR 42Y29

port from trunk revision 652533

Modified:

Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/VerifyAggregateExpressionsVisitor.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java?rev=652622&r1=652621&r2=652622&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/GroupByList.java Thu May  1 11:58:09 2008
@@ -220,6 +220,13 @@
 				*/
 				numColsAddedHere++;
 			}
+			if (groupingCol.getColumnExpression() instanceof JavaToSQLValueNode) 
+			{
+				// disallow any expression which involves native java computation. 
+				// Not possible to consider java expressions for equivalence.
+				throw StandardException.newException(					
+						SQLState.LANG_INVALID_GROUPED_SELECT_LIST);
+			}
 		}
 
 		/* Verify that no subqueries got added to the dummy list */

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/VerifyAggregateExpressionsVisitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/VerifyAggregateExpressionsVisitor.java?rev=652622&r1=652621&r2=652622&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/VerifyAggregateExpressionsVisitor.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/VerifyAggregateExpressionsVisitor.java Thu May  1 11:58:09 2008
@@ -119,15 +119,7 @@
 							SQLState.LANG_INVALID_NON_GROUPED_SELECT_LIST :
 							SQLState.LANG_INVALID_GROUPED_SELECT_LIST);
 			}
-		} else if (node instanceof JavaToSQLValueNode) 
-		{
-			// disallow any expression which involves native java computation. 
-		    	// Not possible to consider java expressions for equivalence.
-			throw StandardException.newException( (groupByList == null) ?
-					SQLState.LANG_INVALID_NON_GROUPED_SELECT_LIST :
-						SQLState.LANG_INVALID_GROUPED_SELECT_LIST);
 		}
-
 		return node;
 	}
 

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java?rev=652622&r1=652621&r2=652622&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java Thu May  1 11:58:09 2008
@@ -478,7 +478,9 @@
         // disallow java function 
         assertCompileError(
                 "42Y30", "select r(), count(*) from test group by r()");
-
+        
+        assertCompileError(
+                "42Y30", "select count(*) from test group by r()");
         // invalid grouping expression.
         assertCompileError(
                 "42Y30", "select c1+1, count(*) from test group by c1+2");

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java?rev=652622&r1=652621&r2=652622&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java Thu May  1 11:58:09 2008
@@ -23,6 +23,7 @@
 
 import java.io.UnsupportedEncodingException;
 import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Time;
@@ -461,6 +462,23 @@
         s.close();
     }
     
+    /**
+     * Test function with an aggregate argument. DERBY-3649
+     * @throws SQLException
+     */
+    public void testAggregateArgument() throws SQLException
+    {
+    	Statement s = createStatement();
+    	s.executeUpdate("CREATE TABLE TEST (I INT)");
+    	s.executeUpdate("INSERT INTO TEST VALUES(1)");
+    	s.executeUpdate("INSERT INTO TEST VALUES(2)");
+    	s.executeUpdate("CREATE FUNCTION CheckCount(count integer) RETURNS INTEGER PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.RoutineTest.checkCount'");
+    	ResultSet rs = s.executeQuery("select checkCount(count(*)) from test");
+    	JDBC.assertSingleValueResultSet(rs, "2");
+    	
+    	
+    }
+    
     /*
     ** Routine implementations called from the tests but do
     *  not use DriverManager so that this test can be used on
@@ -492,5 +510,19 @@
         
         return t;
     }
+    
+
+    public static int checkCount(int count)
+               throws SQLException {
+           //   throws ZeroException {
+
+           if (count == 0) {
+               //throw new ZeroException();
+               throw new SQLException("No results found", "38777");
+           }
+
+           return count;
+       }
+
 }