db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1300622 - in /db/derby/code/branches/10.7: ./ java/engine/org/apache/derby/impl/sql/compile/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ java/testing/org/apache/derbyTesting/functionTests/util/
Date Wed, 14 Mar 2012 16:32:13 GMT
Author: kristwaa
Date: Wed Mar 14 16:32:13 2012
New Revision: 1300622

URL: http://svn.apache.org/viewvc?rev=1300622&view=rev
Log:
DERBY-5614: NullPointerException with INSERT INTO [global temporary table] SELECT ... FROM
[VTI]

Merged fix from trunk (revisions 1294522 and 1295085).

Added:
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
      - copied unchanged from r1295085, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
Modified:
    db/derby/code/branches/10.7/   (props changed)
    db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java

Propchange: db/derby/code/branches/10.7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 14 16:32:13 2012
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.8:1209227-1209228,1209284
-/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1069661,1071463,1071886,1076335,1076387,1078461,1078608,1078693,1081072,1081455,1081568,1085078,1091000,1097247,1103681,1103718,1128243,1129136,1130632,1130895,1131272,1132664,1136363,1138341,1138444,1139449,1141924,1164370,1203050,1207729,1208775,1209228,1243878,1293494,1294512
+/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1069661,1071463,1071886,1076335,1076387,1078461,1078608,1078693,1081072,1081455,1081568,1085078,1091000,1097247,1103681,1103718,1128243,1129136,1130632,1130895,1131272,1132664,1136363,1138341,1138444,1139449,1141924,1164370,1203050,1207729,1208775,1209228,1243878,1293494,1294512,1294522,1295085

Modified: db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java?rev=1300622&r1=1300621&r2=1300622&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
(original)
+++ db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
Wed Mar 14 16:32:13 2012
@@ -862,8 +862,13 @@ public final class InsertNode extends DM
         //
         HasTableFunctionVisitor tableFunctionVisitor = new HasTableFunctionVisitor();
         this.accept( tableFunctionVisitor );
-        if ( tableFunctionVisitor.hasNode() ) { requestBulkInsert(); }
-	}
+        // DERBY-5614: See if the target is a global temporary table (GTT),
+        // in which case we don't support bulk insert.
+        if ( tableFunctionVisitor.hasNode() &&
+                !isSessionSchema(targetTableDescriptor.getSchemaDescriptor())) {
+            requestBulkInsert();
+        }
+    }
 
     /**
      * Request bulk insert optimization at run time.

Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java?rev=1300622&r1=1300621&r2=1300622&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java
Wed Mar 14 16:32:13 2012
@@ -30,6 +30,7 @@ import java.sql.DatabaseMetaData;
 import java.sql.Connection;
 
 import junit.framework.Test;
+import org.apache.derbyTesting.functionTests.util.SampleVTI;
 
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
@@ -1040,7 +1041,8 @@ public class DeclareGlobalTempTableJavaT
         assertUpdateCount(s , 0 , "CREATE TABLE SESSION.t3(c31 int, c32 int)");
         ResultSet rs1 = databaseMetaData.getTables("", null, "%", null);
         while (rs1.next()) {
-            if (("T2" == rs1.getString(3)) && ("SESSION" == rs1.getString(2)))
+            if (("T2".equals(rs1.getString(3))) &&
+                    ("SESSION".equals(rs1.getString(2))))
                 fail("Temporary table Found");
             count++;
         }
@@ -1162,6 +1164,50 @@ public class DeclareGlobalTempTableJavaT
         assertEquals(1, rs1.getInt(2));
         assertUpdateCount(s , 0 , "DROP TABLE SESSION.t2");
     }
+
+    /**
+     * Tests that you can insert data into a GTT with a VTI as the source.
+     * <p>
+     * This used to fail because inserting from a VTI would trigger bulk insert,
+     * but the bulk insert code path is not supported for GTT as the
+     * destination of the insert.
+     * <p>
+     * See DERBY-5614.
+     */
+    public void testVtiInsertIntoGTT()
+            throws SQLException {
+        Statement s = createStatement();
+        s.executeUpdate("DECLARE GLOBAL TEMPORARY TABLE SESSION.vtitogtt(" +
+                "c1 varchar(10)) not logged on commit preserve rows");
+        // Use an empty VTI as the source.
+        s.executeUpdate("CREATE FUNCTION emptySampleVTI() " +
+                "RETURNS TABLE(v1 varchar(10))" +
+                "LANGUAGE JAVA " +
+                "PARAMETER STYLE DERBY_JDBC_RESULT_SET " +
+                "NO SQL " +
+                "EXTERNAL NAME 'org.apache.derbyTesting.functionTests." +
+                "util.SampleVTI.emptySampleVTI'");
+        s.executeUpdate("insert into session.vtitogtt " +
+                "select * from table(emptySampleVTI()) as v");
+        JDBC.assertEmpty(s.executeQuery("select * from session.vtitogtt"));
+        s.executeUpdate("DROP FUNCTION emptySampleVTI");
+
+        // Now try to actually insert some data.
+        s.executeUpdate("CREATE FUNCTION sampleVTI() " +
+                "RETURNS TABLE(v1 varchar(10))" +
+                "LANGUAGE JAVA " +
+                "PARAMETER STYLE DERBY_JDBC_RESULT_SET " +
+                "NO SQL " +
+                "EXTERNAL NAME 'org.apache.derbyTesting.functionTests." +
+                "util.SampleVTI.oneColSampleVTI'");
+        s.executeUpdate("insert into session.vtitogtt " +
+                "select * from table(sampleVTI()) as v");
+        JDBC.assertUnorderedResultSet(
+                s.executeQuery("select * from session.vtitogtt"),
+                SampleVTI.oneColSampleVTIData());
+        s.executeUpdate("DROP FUNCTION sampleVTI");
+    }
+
     /**
      * 
      * A Utility method that deletes all the SESSION schema tables before each fixture.
@@ -1170,26 +1216,17 @@ public class DeclareGlobalTempTableJavaT
      */
     public void dropSchemaTables() throws SQLException {
         Statement s = createStatement();
-        try {
-            s.executeUpdate("DROP TABLE SESSION.t1");
-        } catch (SQLException e) {
-        }
-        try {
-            s.executeUpdate("DROP TABLE SESSION.t2");
-        } catch (SQLException e) {
-        }
-        try {
-            s.executeUpdate("DROP TABLE SESSION.t3");
-        } catch (SQLException e) {
-        }
-        try {
-            s.executeUpdate("DROP TABLE SESSION.t4");
-        } catch (SQLException e) {
-        }
-        try {
-            s.executeUpdate("DROP TABLE SESSION.t5");
-        } catch (SQLException e) {
+        // Query the meta data to avoid filling the log with lots of
+        // table-not-found error messages.
+        ResultSet rs = getConnection().getMetaData().getTables(
+                null, "SESSION", "%", null);
+        while (rs.next()) {
+            try {
+                s.executeUpdate("DROP TABLE " + rs.getString(2) + "." +
+                        rs.getString(3));
+            } catch (SQLException e) {
+            }
         }
+        rs.close();
     }
 }
-



Mime
View raw message