db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1616529 - in /db/derby/code/branches/10.11: ./ java/engine/org/apache/derby/impl/sql/compile/ java/engine/org/apache/derby/loc/ java/shared/org/apache/derby/shared/common/reference/ java/testing/org/apache/derbyTesting/functionTests/tests/...
Date Thu, 07 Aug 2014 16:35:36 GMT
Author: dag
Date: Thu Aug  7 16:35:35 2014
New Revision: 1616529

URL: http://svn.apache.org/r1616529
Log:
DERBY-6693 Assert failure/ArrayIndexOutOfBoundsException when using COUNT in MERGE matching
clause

Backported from trunk cleanly as:

svn merge -c 1616523 https://svn.apache.org/repos/asf/db/derby/code/trunk

The patch forbids aggregates in the matching clauses, and adds a test
case to MergeStatementTest.


Modified:
    db/derby/code/branches/10.11/   (props changed)
    db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
    db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/branches/10.11/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java

Propchange: db/derby/code/branches/10.11/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1616523

Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java?rev=1616529&r1=1616528&r2=1616529&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
(original)
+++ db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
Thu Aug  7 16:35:35 2014
@@ -388,11 +388,30 @@ public final class MergeNode extends DML
 
             // window function not allowed
             SelectNode.checkNoWindowFunctions(mcn, "matching clause");
+
+            // aggregates not allowed
+            checkNoAggregates(mcn);
         }
         
         bindLeftJoin( dd );
 	}
 
+
+    static void checkNoAggregates(QueryTreeNode clause)
+            throws StandardException {
+
+        // Clause cannot contain window aggregates except inside subqueries
+        HasNodeVisitor visitor = new HasNodeVisitor(AggregateNode.class,
+                                                    SubqueryNode.class);
+        clause.accept(visitor);
+
+        if (visitor.hasNode()) {
+            throw StandardException.newException(
+                    SQLState.LANG_NO_AGGREGATES_IN_MERGE_MATCHING_CLAUSE);
+        }
+    }
+
+
     /////////////////////////////////////
     //
     // TABLE AND CORRELATION CHECKS

Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml?rev=1616529&r1=1616528&r2=1616529&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml Thu Aug  7
16:35:35 2014
@@ -2883,6 +2883,11 @@ Guide.
             </msg>
 
             <msg>
+                <name>42Z09</name>
+                <text>Aggregates are not permitted in the MERGE matching clause.</text>
+            </msg>
+
+            <msg>
                 <name>42Z15</name>
                 <text>Invalid type specified for column '{0}'. The type of a column
may not be changed.  </text>
                 <arg>columnName</arg>

Modified: db/derby/code/branches/10.11/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1616529&r1=1616528&r2=1616529&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/branches/10.11/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Thu Aug  7 16:35:35 2014
@@ -1051,6 +1051,7 @@ public interface SQLState {
 	String LANG_USER_AGGREGATE_MULTIPLE_DISTINCTS                      = "42Z02";
 	String LANG_NO_AGGREGATES_IN_ON_CLAUSE                             = "42Z07";
 	String LANG_NO_BULK_INSERT_REPLACE_WITH_TRIGGER                    = "42Z08";
+    String LANG_NO_AGGREGATES_IN_MERGE_MATCHING_CLAUSE                 = "42Z09";
 
 	// MORE GENERIC LANGUAGE STUFF
 	String LANG_UDT_BUILTIN_CONFLICT										   = "42Z10";

Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java?rev=1616529&r1=1616528&r2=1616529&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
(original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
Thu Aug  7 16:35:35 2014
@@ -29,6 +29,7 @@ import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Arrays;
 import junit.framework.Test;
@@ -78,6 +79,7 @@ public class MergeStatementTest extends 
     private static  final   String      NO_DCL_IN_MERGE = "42XAQ";
     private static  final   String      PARAMETER_NOT_SET = "07000";
     private static  final   String      CARDINALITY_VIOLATION = "21000";
+    private static  final   String      NO_AGGREGATE_IN_MATCHING = "42Z09";
 
     private static  final   String[]    TRIGGER_HISTORY_COLUMNS = new String[] { "ACTION",
"ACTION_VALUE" };
 
@@ -9505,6 +9507,23 @@ public class MergeStatementTest extends 
         goodStatement( dboConnection, "drop table t1_060" );
         goodStatement( dboConnection, "drop table t2_060" );
     }
+
+    public void test_061_Derby6693() throws SQLException {
+        Statement s = createStatement();
+
+        try {
+            s.execute("create table t2(x int)");
+            s.execute("create table t1(x int)");
+            s.execute("insert into t2 values 3,4");
+            assertCompileError(
+                    NO_AGGREGATE_IN_MATCHING,
+                    "merge into t1 using t2 on (t1.x=t2.x) " +
+                    "when not matched then insert values (max(t2.x))");
+        } finally {
+            dropTable("t1");
+            dropTable("t2");
+        }
+    }
     
     ///////////////////////////////////////////////////////////////////////////////////
     //



Mime
View raw message