db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1295085 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/functionTests/util/
Date Wed, 29 Feb 2012 13:07:24 GMT
Author: kristwaa
Date: Wed Feb 29 13:07:23 2012
New Revision: 1295085

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

Disables bulk-insert for GTTs when selecting from a VTI.
Added a new test case.
Added SampleVTI, which is an incomplete (only supports a few getters) VTI
intended for basic testing.

Patch file: derby-5614-1b-disable_bulkinsert_gtt.diff

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java?rev=1295085&r1=1295084&r2=1295085&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java Wed
Feb 29 13:07:23 2012
@@ -867,8 +867,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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java?rev=1295085&r1=1295084&r2=1295085&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DeclareGlobalTempTableJavaTest.java
Wed Feb 29 13:07:23 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;
@@ -1163,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.
@@ -1171,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();
     }
 }
-

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java?rev=1295085&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
Wed Feb 29 13:07:23 2012
@@ -0,0 +1,285 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.util.SampleVTI
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.derbyTesting.functionTests.util;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+import org.apache.derby.vti.VTITemplate;
+
+/**
+ * A very simple, read-only, sample VTI.
+ * <p>
+ * This VTI is incomplete and has its quirks - it is intended for basic testing
+ * only! Supported getters:
+ * <ul> <li>getString</li>
+ *      <li>getInt</li>
+ * </ul>
+ */
+public class SampleVTI
+    extends VTITemplate {
+
+    private static final String[][] oneColData = new String[][] {
+            {"one"}, {"two"}, {"three"}, {"four"}, {"five"}
+        };
+
+    /** Returns a sample VTI that is empty (has zero rows). */
+    public static ResultSet emptySampleVTI() {
+        return new SampleVTI(new String[0][0]);
+    }
+
+    /**
+     * Returns a sample VTI with the some test data.
+     *
+     *@return A result set with a single column with string data (five rows).
+     */
+    public static ResultSet oneColSampleVTI() {
+        return new SampleVTI(oneColData);
+    }
+
+    public static String[][] oneColSampleVTIData() {
+        return (String[][])oneColData.clone();
+    }
+
+    private final String[][] data;
+    private final int rows;
+    private final int cols;
+    private int index = -1;
+    private boolean wasNull;
+    private boolean closed;
+
+    private SampleVTI(String[][] data) {
+        this.data = data;
+        this.rows = data.length;
+        this.cols = rows == 0 ? 0 : data[0].length;
+    }
+
+    private String getColumn(int columnIndex)
+            throws SQLException {
+        if (closed) {
+            throw new SQLException("result set closed");
+        }
+        if (columnIndex < 1 || columnIndex > cols) {
+            throw new SQLException("column value out of range");
+        }
+        String val = data[index][columnIndex -1];
+        wasNull = val == null;
+        return val;
+    }
+
+    //@Override
+    public ResultSetMetaData getMetaData() throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    //@Override
+    public boolean next() throws SQLException {
+        if (closed) {
+            throw new SQLException("result set closed");
+        }
+        return ++index < rows;
+    }
+
+    //@Override
+    public void close() throws SQLException {
+        this.closed = true;
+    }
+
+    //@Override
+    public String getString(int columnIndex)
+            throws SQLException {
+        return getColumn(columnIndex);
+    }
+
+    //@Override
+    public int getInt(int columnIndex)
+            throws SQLException {
+        String raw = getColumn(columnIndex);
+        if (wasNull) {
+            raw = "0";
+        }
+        try {
+            return Integer.parseInt(raw);
+        } catch (NumberFormatException nfe) {
+            throw new SQLException("cannot get value as int");
+        }
+    }
+
+    //@Override
+    public boolean wasNull() {
+        return wasNull;
+    }
+
+    public int getHoldability() throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public boolean isClosed() throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNString(int columnIndex, String nString) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNString(String columnLabel, String nString) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public String getNString(int columnIndex) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public String getNString(String columnLabel) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public Reader getNCharacterStream(int columnIndex) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public Reader getNCharacterStream(String columnLabel) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws
SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateAsciiStream(String columnLabel, InputStream x, long length) throws
SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBinaryStream(String columnLabel, InputStream x, long length) throws
SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateCharacterStream(String columnLabel, Reader reader, long length) throws
SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBlob(int columnIndex, InputStream inputStream, long length) throws
SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBlob(String columnLabel, InputStream inputStream, long length) throws
SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateClob(int columnIndex, Reader reader, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateClob(String columnLabel, Reader reader, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException
{
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateClob(int columnIndex, Reader reader) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateClob(String columnLabel, Reader reader) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void updateNClob(String columnLabel, Reader reader) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public Object getObject(int columnIndex, Class type) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public Object getObject(String columnLabel, Class type) throws SQLException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SampleVTI.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message