Search in sources :

Example 86 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestAdhocAlterTable method testAlterDropColumn.

@Test
public void testAlterDropColumn() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table FOO (" + "PKCOL integer not null," + "DROPME bigint, " + "PROCCOL bigint, " + "VIEWCOL bigint, " + "INDEXCOL bigint, " + "INDEX1COL bigint, " + "INDEX2COL bigint, " + "constraint pk_tree primary key (PKCOL)" + ");\n" + "create procedure BAR as select PROCCOL from FOO;\n" + "create view FOOVIEW (VIEWCOL, TOTAL) as select VIEWCOL, COUNT(*) from FOO group by VIEWCOL;\n" + "create index FOODEX on FOO(INDEXCOL);\n" + "create index FOO2DEX on FOO(INDEX1COL, INDEX2COL);\n" + "create table ONECOL (" + "SOLOCOL integer, " + ");\n" + "create table BAZ (" + "PKCOL1 integer not null, " + "PKCOL2 integer not null, " + "constraint pk_tree2 primary key (PKCOL1, PKCOL2)" + ");\n");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        // Basic alter drop, should work
        assertTrue(doesColumnExist("FOO", "DROPME"));
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column DROPME;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to drop a bare column.");
        }
        assertFalse(doesColumnExist("FOO", "DROPME"));
        // but not twice
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column DROPME; --commentfortesting");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a column that doesn't exist", threw);
        assertFalse(doesColumnExist("FOO", "DROPME"));
        // Can't drop column used by procedure
        assertTrue(doesColumnExist("FOO", "PROCCOL"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column PROCCOL;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a column used by a procedure", threw);
        assertTrue(doesColumnExist("FOO", "PROCCOL"));
        try {
            m_client.callProcedure("BAR");
        } catch (ProcCallException pce) {
            fail("Procedure should still exist.");
        }
        // Can't drop a column used by a view
        assertTrue(doesColumnExist("FOO", "VIEWCOL"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column VIEWCOL;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a column used by a view", threw);
        assertTrue(doesColumnExist("FOO", "VIEWCOL"));
        assertTrue(findTableInSystemCatalogResults("FOOVIEW"));
        // unless you use cascade
        assertTrue(doesColumnExist("FOO", "VIEWCOL"));
        assertTrue(findTableInSystemCatalogResults("FOOVIEW"));
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column VIEWCOL cascade; --comment messes up cascade?");
        } catch (ProcCallException pce) {
            fail("Dropping a column should drop a view with cascade");
        }
        assertFalse(doesColumnExist("FOO", "VIEWCOL"));
        assertFalse(findTableInSystemCatalogResults("FOOVIEW"));
        // single-column indexes get cascaded automagically
        assertTrue(doesColumnExist("FOO", "INDEXCOL"));
        assertTrue(findIndexInSystemCatalogResults("FOODEX"));
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column INDEXCOL;");
        } catch (ProcCallException pce) {
            fail("Should be able to drop a single column backing a single column index.");
        }
        assertFalse(doesColumnExist("FOO", "INDEXCOL"));
        assertFalse(findIndexInSystemCatalogResults("FOODEX"));
        // single-column primary keys get cascaded automagically
        assertTrue(doesColumnExist("FOO", "PKCOL"));
        assertTrue(findIndexInSystemCatalogResults("VOLTDB_AUTOGEN_CONSTRAINT_IDX_PK_TREE"));
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column PKCOL;");
        } catch (ProcCallException pce) {
            fail("Should be able to drop a single column backing a single column primary key.");
        }
        assertFalse(doesColumnExist("FOO", "PKCOL"));
        assertFalse(findIndexInSystemCatalogResults("VOLTDB_AUTOGEN_CONSTRAINT_IDX_PK_TREE"));
        // WEIRD: this seems like weird behavior to me still --izzy
        // Dropping a column used by a multi-column index drops the index
        assertTrue(doesColumnExist("FOO", "INDEX1COL"));
        assertTrue(findIndexInSystemCatalogResults("FOO2DEX"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO drop column INDEX1COL;");
        } catch (ProcCallException pce) {
            fail("Dropping a column used by an index should kill the index");
        }
        assertFalse(doesColumnExist("FOO", "INDEX1COL"));
        assertFalse(findIndexInSystemCatalogResults("FOO2DEX"));
        // Can't drop a column used by a multi-column primary key
        assertTrue(doesColumnExist("BAZ", "PKCOL1"));
        assertTrue(findIndexInSystemCatalogResults("VOLTDB_AUTOGEN_CONSTRAINT_IDX_PK_TREE2"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table BAZ drop column PKCOL1;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        System.out.println("COLUMNS: " + m_client.callProcedure("@SystemCatalog", "COLUMNS").getResults()[0]);
        System.out.println("INDEXES: " + m_client.callProcedure("@SystemCatalog", "INDEXINFO").getResults()[0]);
        assertTrue("Shouldn't be able to drop a column used by a multi-column primary key", threw);
        assertTrue(doesColumnExist("BAZ", "PKCOL1"));
        assertTrue(findIndexInSystemCatalogResults("VOLTDB_AUTOGEN_CONSTRAINT_IDX_PK_TREE2"));
        // Can't drop the last column in a table
        assertTrue(doesColumnExist("ONECOL", "SOLOCOL"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table BAZ drop column PKCOL1;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop the last column in a table", threw);
        assertTrue(doesColumnExist("ONECOL", "SOLOCOL"));
    } finally {
        teardownSystem();
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 87 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TPCDataPrinter method printAllData.

public static void printAllData(Client client) {
    VoltTable[] tables = null;
    try {
        tables = client.callProcedure("SelectAll").getResults();
    } catch (ProcCallException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    for (int i : indexMap.keySet()) {
        VoltTable table = tables[i];
        String name = indexMap.get(i);
        System.out.println("===============================");
        System.out.println("Table " + name + " has " + table.getRowCount() + " rows.");
        printTable(table);
    }
}
Also used : IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 88 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestAdhocAlterTable method testAlterAddColumn.

@Test
public void testAlterAddColumn() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table FOO (" + "ID integer not null," + "VAL bigint, " + "constraint pk_tree primary key (ID)" + ");\n");
    builder.addPartitionInfo("FOO", "ID");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO add column NEWCOL varchar(50);");
        } catch (ProcCallException pce) {
            fail("Alter table to add column should have succeeded");
        }
        assertTrue(verifyTableColumnType("FOO", "NEWCOL", "VARCHAR"));
        assertTrue(verifyTableColumnSize("FOO", "NEWCOL", 50));
        assertTrue(isColumnNullable("FOO", "NEWCOL"));
        // second time should fail
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO add column NEWCOL varchar(50);");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Adding the same column twice should fail", threw);
        // can't add another primary key
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO add column BADPK integer primary key;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to add a second primary key", threw);
        // Can't add a not-null column with no default
        // NOTE: this could/should work with an empty table, but HSQL apparently
        // doesn't let it get that far.
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO add column BADNOTNULL integer not null;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertFalse("Should be able to add a not null column to an empty table without default", threw);
        // but we're good with a default
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO add column GOODNOTNULL integer default 0 not null;");
        } catch (ProcCallException pce) {
            fail("Should be able to add a column with not null and a default.");
        }
        assertTrue(verifyTableColumnType("FOO", "GOODNOTNULL", "INTEGER"));
        assertFalse(isColumnNullable("FOO", "GOODNOTNULL"));
        // Can't add a column with a bad definition
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "alter table FOO add column BADVARCHAR varchar(0) not null;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to add a column with a bad definition", threw);
        assertFalse(doesColumnExist("FOO", "BADVARCHAR"));
    } finally {
        teardownSystem();
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 89 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestRoutingEdgeCases method testPartitionKeyAsBytes.

/**
     * Insert into a <8byte integer column using byte[] to send
     * the int. The column is also the partition column. Make sure
     * TheHashinator doesn't screw up.
     */
@Test
public void testPartitionKeyAsBytes() throws Exception {
    ServerThread localServer = null;
    Client client = null;
    try {
        String simpleSchema = "create table blah (" + "ival integer default 0 not null, " + "PRIMARY KEY(ival)); " + "PARTITION TABLE blah ON COLUMN ival;";
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addLiteralSchema(simpleSchema);
        builder.addStmtProcedure("Insert", "insert into blah values (?);", null);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("edgecases.jar"), 7, 1, 0);
        assert (success);
        MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("edgecases.xml"));
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = Configuration.getPathToCatalogForTest("edgecases.jar");
        config.m_pathToDeployment = Configuration.getPathToCatalogForTest("edgecases.xml");
        localServer = new ServerThread(config);
        localServer.start();
        localServer.waitForInitialization();
        client = ClientFactory.createClient();
        client.createConnection("localhost");
        try {
            ByteBuffer buf = ByteBuffer.allocate(4);
            buf.order(ByteOrder.LITTLE_ENDIAN);
            buf.putInt(7);
            byte[] value = buf.array();
            client.callProcedure("Insert", value);
            fail();
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("Array / Scalar parameter mismatch"));
        }
    // For now, @LoadSinglepartitionTable assumes 8 byte integers, even if type is < 8 bytes
    // This is ok because we don't expose this functionality.
    // The code below will throw a constraint violation, but it really shouldn't. There's
    // Another comment about this in ProcedureRunner about a reasonable fix for this.
    //VoltTable t = new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.INTEGER));
    //t.addRow(13);
    //
    //ByteBuffer buf = ByteBuffer.allocate(4);
    //buf.order(ByteOrder.LITTLE_ENDIAN);
    //buf.putInt(13);
    //byte[] value = buf.array();
    //client.callProcedure("@LoadSinglepartitionTable", value, "blah", t);
    } finally {
        if (client != null)
            client.close();
        if (localServer != null)
            localServer.shutdown();
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) Client(org.voltdb.client.Client) ByteBuffer(java.nio.ByteBuffer) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 90 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestCatchExceptionsInProcedure method mpChecker.

private void mpChecker(Client client, int hasPreviousBatch, int tryCatchContains1Batch, int hasFollowingBatch) throws NoConnectionsException, IOException, ProcCallException {
    VoltTable vt;
    String sql;
    final String MPErrorMessage = "attempted to execute new batch " + "after hitting EE exception in a previous batch";
    String[] procs = { "MPInsertOnReplicatedTable", "MPInsertOnPartitionTable" };
    String[] tables = { "R1", "P1" };
    int[] followingBatchHasExceptions = { 0, 1 };
    for (int i = 0; i < procs.length; i++) {
        String proc = procs[i];
        String tb = tables[i];
        for (int followingBatchHasException : followingBatchHasExceptions) {
            try {
                vt = client.callProcedure(proc, hasPreviousBatch, tryCatchContains1Batch, hasFollowingBatch, followingBatchHasException).getResults()[0];
                // validate returned value from the procedure calls
                validateRowOfLongs(vt, new long[] { -1 });
            } catch (Exception e) {
                assertTrue(e.getMessage().contains(MPErrorMessage));
            }
            sql = "select ratio from " + tb + " order by 1;";
            // empty table
            validateTableColumnOfScalarFloat(client, sql, new double[] {});
            // empty table
            sql = "select count(*) from " + tb;
            validateTableOfScalarLongs(client, sql, new long[] { 0 });
            client.callProcedure("@AdHoc", "truncate table " + tb);
        }
    }
}
Also used : VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException)

Aggregations

ProcCallException (org.voltdb.client.ProcCallException)240 Client (org.voltdb.client.Client)151 VoltTable (org.voltdb.VoltTable)120 ClientResponse (org.voltdb.client.ClientResponse)92 IOException (java.io.IOException)82 NoConnectionsException (org.voltdb.client.NoConnectionsException)55 Test (org.junit.Test)44 Configuration (org.voltdb.VoltDB.Configuration)41 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)36 File (java.io.File)21 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)19 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 VoltDB (org.voltdb.VoltDB)10 VoltTableRow (org.voltdb.VoltTableRow)10 Timestamp (java.sql.Timestamp)5 TimestampType (org.voltdb.types.TimestampType)5 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 HashSet (java.util.HashSet)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3