Search in sources :

Example 16 with VoltProjectBuilder

use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.

the class TestAdhocDropTable method testDropTableBasic.

@Test
public void testDropTableBasic() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table BLAH (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create table DROPME (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID))\n;" + "create table DROPME_R (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));");
    builder.addPartitionInfo("BLAH", "ID");
    builder.addPartitionInfo("DROPME", "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);
        // Check basic drop of partitioned table that should work.
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("DROPME"));
        // eng7297, start with 6 rows in @Statistics table (one per table per site)
        VoltTable stats = getStatWaitOnRowCount("TABLE", 6);
        assertEquals(6, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 6);
        assertEquals(6, stats.getRowCount());
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("DROPME"));
        // eng7297, now only 4 rows in @Statistics table (one per table per site)
        stats = getStatWaitOnRowCount("TABLE", 4);
        assertEquals(4, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 4);
        assertEquals(4, stats.getRowCount());
        // Check basic drop of replicated table that should work.
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("DROPME_R"));
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME_R;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("DROPME_R"));
        // eng7297, now only 2 rows in @Statistics table (one per table per site)
        stats = getStatWaitOnRowCount("TABLE", 2);
        assertEquals(2, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 2);
        assertEquals(2, stats.getRowCount());
        // Verify dropping a table that doesn't exist fails
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME;");
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("object not found: DROPME"));
            threw = true;
        }
        assertTrue("Dropping bad table should have failed", threw);
        // Verify dropping a table that doesn't exist is fine with IF EXISTS
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME IF EXISTS;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertFalse("Dropping bad table with IF EXISTS should not have failed", threw);
        // ENG-7297, Drop the last table and make sure that the statistics are correct
        try {
            m_client.callProcedure("@AdHoc", "drop table BLAH;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("BLAH"));
        // eng7297, now should be zero rows in the stats
        stats = getStatWaitOnRowCount("TABLE", 0);
        assertEquals(0, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 0);
        assertEquals(0, stats.getRowCount());
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) 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 17 with VoltProjectBuilder

use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.

the class TestAdhocDropTable method testDropTableWithIndexesAndProcedures.

@Test
public void testDropTableWithIndexesAndProcedures() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table BLAH (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create table VIEWBASE (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create table DROPME (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create assumeunique index pkey_idx on DROPME(VAL);\n" + "create view BLAT (VAL, TOTAL) as select VAL, COUNT(*) from VIEWBASE group by VAL;\n");
    builder.addPartitionInfo("BLAH", "ID");
    builder.addPartitionInfo("DROPME", "ID");
    builder.addStmtProcedure("BLERG", "select * from BLAH where 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);
        // Check basic drop of table with an index on it
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("DROPME"));
        resp = m_client.callProcedure("@SystemCatalog", "INDEXINFO");
        System.out.println(resp.getResults()[0]);
        assertTrue(findIndexInSystemCatalogResults("PKEY_IDX"));
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("DROPME"));
        resp = m_client.callProcedure("@SystemCatalog", "INDEXINFO");
        System.out.println(resp.getResults()[0]);
        assertFalse(findIndexInSystemCatalogResults("PKEY_IDX"));
        // Verify that we can't drop a table that a procedure depends on
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("BLAH"));
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table BLAH;");
        } catch (ProcCallException pce) {
            // The error message is really confusing for this case, not sure
            // how to make it better though
            pce.printStackTrace();
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a table used in a procedure", threw);
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("BLAH"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table VIEWBASE;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a table used in a view", threw);
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("VIEWBASE"));
        assertTrue(findTableInSystemCatalogResults("BLAT"));
        try {
            m_client.callProcedure("@AdHoc", "drop table VIEWBASE cascade;");
        } catch (ProcCallException pce) {
            fail("Should be able to drop table and view with cascade");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("VIEWBASE"));
        assertFalse(findTableInSystemCatalogResults("BLAT"));
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) 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 18 with VoltProjectBuilder

use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.

the class TestAdhocCreateDropView method testBasicCreateView.

@Test
public void testBasicCreateView() 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" + "create table FOO_R (" + "ID integer not null," + "VAL bigint, " + "constraint PK_TREE_R 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);
        // create a basic view
        assertFalse(findTableInSystemCatalogResults("FOOVIEW"));
        try {
            m_client.callProcedure("@AdHoc", "create view FOOVIEW (VAL, TOTAL) as " + "select VAL, COUNT(*) from FOO group by VAL;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to create a view");
        }
        assertTrue(findTableInSystemCatalogResults("FOOVIEW"));
        // can't do it again
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "create view FOOVIEW (VAL, TOTAL) as " + "select VAL, COUNT(*) from FOO group by VAL;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to create the same view twice", threw);
        assertTrue(findTableInSystemCatalogResults("FOOVIEW"));
        // drop it like it's hot
        try {
            m_client.callProcedure("@AdHoc", "drop view FOOVIEW;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to drop a view");
        }
        assertFalse(findTableInSystemCatalogResults("FOOVIEW"));
        // Not a second time
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop view FOOVIEW;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a view twice", threw);
        assertFalse(findTableInSystemCatalogResults("FOOVIEW"));
        // unless if exists is there
        try {
            m_client.callProcedure("@AdHoc", "drop view FOOVIEW if exists;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to drop a bad view with if exists");
        }
        assertFalse(findTableInSystemCatalogResults("FOOVIEW"));
    } 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 19 with VoltProjectBuilder

use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.

the class TestAdhocCreateTable method testMultiLineCreateTable.

// Test creating a table when we feed a statement containing newlines.
// I honestly didn't expect this to work yet --izzy
@Test
public void testMultiLineCreateTable() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("--dont care");
    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);
        // Check basic drop of partitioned table that should work.
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertFalse(findTableInSystemCatalogResults("FOO"));
        System.out.println(resp.getResults()[0]);
        try {
            m_client.callProcedure("@AdHoc", "create table FOO (\n" + "ID int default 0 not null,\n" + "VAL varchar(32 bytes)\n" + ");");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("create table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("FOO"));
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) 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 20 with VoltProjectBuilder

use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.

the class TestAdhocCreateTable method testCreatePartitionedTable.

@Test
public void testCreatePartitionedTable() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("--dont care");
    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);
        // Check basic create of partitioned table that should work.
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertFalse(findTableInSystemCatalogResults("FOO"));
        System.out.println(resp.getResults()[0]);
        try {
            m_client.callProcedure("@AdHoc", "create table FOO (\n" + "ID int default 0 not null,\n" + "VAL varchar(32 bytes),\n" + "VAL2 bigint not null assumeunique\n" + ");\n" + "partition table FOO on column ID;\n");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("create table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("FOO"));
        assertTrue(isColumnPartitionColumn("FOO", "ID"));
        // This, however, not being batched, won't work until the empty table
        // check goes in.
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertFalse(findTableInSystemCatalogResults("BAR"));
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "create table BAR (\n" + "ID int default 0 not null,\n" + "VAL varchar(32 bytes),\n" + // (starts replicated) and partition it in a separate @AdHoc call
            "VAL2 bigint not null assumeunique,\n" + "constraint blerg assumeunique(VAL)\n" + ");\n");
            m_client.callProcedure("@AdHoc", "partition table BAR on column ID;\n");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            threw = true;
        }
        assertFalse("Failed to partition an already created table.", threw);
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertTrue(findTableInSystemCatalogResults("BAR"));
        assertTrue(isColumnPartitionColumn("BAR", "ID"));
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Aggregations

VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)269 Configuration (org.voltdb.VoltDB.Configuration)89 IOException (java.io.IOException)49 Test (org.junit.Test)45 File (java.io.File)40 ProcCallException (org.voltdb.client.ProcCallException)38 ClientResponse (org.voltdb.client.ClientResponse)37 VoltDB (org.voltdb.VoltDB)22 LocalCluster (org.voltdb.regressionsuites.LocalCluster)18 Client (org.voltdb.client.Client)17 Before (org.junit.Before)14 HashMap (java.util.HashMap)13 VoltTable (org.voltdb.VoltTable)13 ServerThread (org.voltdb.ServerThread)12 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)12 VoltCompiler (org.voltdb.compiler.VoltCompiler)11 HttpResponse (org.apache.http.HttpResponse)10 BeforeClass (org.junit.BeforeClass)8 ClientConfig (org.voltdb.client.ClientConfig)7 UserInfo (org.voltdb.compiler.VoltProjectBuilder.UserInfo)7