Search in sources :

Example 36 with Catalog

use of org.voltdb.catalog.Catalog in project voltdb by VoltDB.

the class TestVoltCompiler method testValidNonAnnotatedProcedureDDL.

public void testValidNonAnnotatedProcedureDDL() throws Exception {
    String schema = "create table books" + " (cash integer default 23 not null," + " title varchar(3) default 'foo'," + " PRIMARY KEY(cash));" + "PARTITION TABLE books ON COLUMN cash;" + "create procedure from class org.voltdb.compiler.procedures.NotAnnotatedAddBook;" + "paRtItiOn prOcEdure NotAnnotatedAddBook On taBLe   books coLUmN cash   ParaMETer  0;";
    VoltCompiler compiler = new VoltCompiler(false);
    final boolean success = compileDDL(schema, compiler);
    assertTrue(success);
    String catalogContents = VoltCompilerUtils.readFileFromJarfile(testout_jar, "catalog.txt");
    Catalog c2 = new Catalog();
    c2.execute(catalogContents);
    Database db = c2.getClusters().get("cluster").getDatabases().get("database");
    Procedure addBook = db.getProcedures().get("NotAnnotatedAddBook");
    assertTrue(addBook.getSinglepartition());
}
Also used : Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure) Catalog(org.voltdb.catalog.Catalog)

Example 37 with Catalog

use of org.voltdb.catalog.Catalog in project voltdb by VoltDB.

the class TestVoltCompiler method checkDDLAgainstGivenSchema.

private Database checkDDLAgainstGivenSchema(String errorRegex, String givenSchema, String... ddl) throws Exception {
    String schemaDDL = givenSchema + StringUtils.join(ddl, " ");
    VoltCompiler compiler = new VoltCompiler(false);
    boolean success;
    String error;
    try {
        success = compileDDL(schemaDDL, compiler);
        error = (success || compiler.m_errors.size() == 0 ? "" : compiler.m_errors.get(compiler.m_errors.size() - 1).message);
    } catch (HsqlException hex) {
        success = false;
        error = hex.getMessage();
    } catch (PlanningErrorException plex) {
        success = false;
        error = plex.getMessage();
    }
    if (errorRegex == null) {
        assertTrue(String.format("Expected success\nDDL: %s\n%s", StringUtils.join(ddl, " "), error), success);
        Catalog cat = compiler.getCatalog();
        return cat.getClusters().get("cluster").getDatabases().get("database");
    } else {
        assertFalse(String.format("Expected error (\"%s\")\nDDL: %s", errorRegex, StringUtils.join(ddl, " ")), success);
        assertFalse("Expected at least one error message.", error.isEmpty());
        Matcher m = Pattern.compile(errorRegex).matcher(error);
        assertTrue(String.format("%s\nEXPECTED: %s", error, errorRegex), m.matches());
        return null;
    }
}
Also used : PlanningErrorException(org.voltdb.planner.PlanningErrorException) Matcher(java.util.regex.Matcher) HsqlException(org.hsqldb_voltpatches.HsqlException) Catalog(org.voltdb.catalog.Catalog)

Example 38 with Catalog

use of org.voltdb.catalog.Catalog in project voltdb by VoltDB.

the class TestVoltCompiler method compileLimitDeleteStmtAndCheckCatalog.

void compileLimitDeleteStmtAndCheckCatalog(String ddl, String expectedMessage, String tblName, int expectedLimit, String expectedStmt) {
    VoltCompiler compiler = new VoltCompiler(false);
    boolean success = compileDDL(ddl, compiler);
    checkCompilerErrorMessages(expectedMessage, compiler, success);
    if (success) {
        // We expected  success and got it.  Verify that the catalog looks how we expect
        Catalog cat = compiler.getCatalog();
        Table tbl = cat.getClusters().get("cluster").getDatabases().get("database").getTables().getIgnoreCase(tblName);
        if (expectedLimit != -1) {
            assertEquals(expectedLimit, tbl.getTuplelimit());
        } else {
            // no limit is represented as a limit of max int.
            assertEquals(Integer.MAX_VALUE, tbl.getTuplelimit());
        }
        String stmt = CatalogUtil.getLimitPartitionRowsDeleteStmt(tbl);
        if (expectedStmt == null) {
            assertNull("Did not expect to find a LIMIT DELETE statement, but found this one:\n" + (stmt != null ? stmt : ""), stmt);
        } else {
            // Make sure we have the delete statement that we expected
            assertNotNull("Expected to find LIMIT DELETE statement, found none", stmt);
            if (stmt.endsWith(";")) {
                // We seem to add a semicolon somewhere.  I guess that's okay.
                stmt = stmt.substring(0, stmt.length() - 1);
            }
            // Remove spaces from both strings so we compare whitespace insensitively
            // Capturing the DELETE statement in HSQL does not preserve whitespace.
            expectedStmt = stmt.replace(" ", "");
            stmt = stmt.replace(" ", "");
            assertEquals("Did not find the LIMIT DELETE statement that we expected", expectedStmt, stmt);
        }
    }
}
Also used : Table(org.voltdb.catalog.Table) Catalog(org.voltdb.catalog.Catalog)

Example 39 with Catalog

use of org.voltdb.catalog.Catalog in project voltdb by VoltDB.

the class TestVoltCompiler method testDdlProcVarbinary.

public void testDdlProcVarbinary() throws IOException {
    String schema = "create table books" + "  (cash integer default 23 NOT NULL," + "  title varbinary(10) default NULL," + "  PRIMARY KEY(cash));" + "partition table books on column cash;" + "create procedure get as select * from books;" + "create procedure i1 as insert into books values(5, 'AA');" + "create procedure i2 as insert into books values(5, ?);" + "create procedure s1 as update books set title = 'bb';" + "create procedure i3 as insert into books values( ?, ?);" + "partition procedure i3 on table books column cash;" + "create procedure d1 as" + "  delete from books where title = ? and cash = ?;" + "partition procedure d1 on table books column cash parameter 1;";
    VoltCompiler compiler = new VoltCompiler(false);
    final boolean success = compileDDL(schema, compiler);
    assertTrue(success);
    Catalog c1 = compiler.getCatalog();
    String catalogContents = VoltCompilerUtils.readFileFromJarfile(testout_jar, "catalog.txt");
    Catalog c2 = new Catalog();
    c2.execute(catalogContents);
    assertTrue(c2.serialize().equals(c1.serialize()));
}
Also used : Catalog(org.voltdb.catalog.Catalog)

Example 40 with Catalog

use of org.voltdb.catalog.Catalog in project voltdb by VoltDB.

the class TestVoltCompiler method testValidAnnotatedProcedureDLL.

public void testValidAnnotatedProcedureDLL() throws Exception {
    String schema = "create table books" + " (cash integer default 23 not null," + " title varchar(3) default 'foo'," + " PRIMARY KEY(cash));" + "PARTITION TABLE books ON COLUMN cash;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook;";
    VoltCompiler compiler = new VoltCompiler(false);
    final boolean success = compileDDL(schema, compiler);
    assertTrue(success);
    String catalogContents = VoltCompilerUtils.readFileFromJarfile(testout_jar, "catalog.txt");
    Catalog c2 = new Catalog();
    c2.execute(catalogContents);
    Database db = c2.getClusters().get("cluster").getDatabases().get("database");
    Procedure addBook = db.getProcedures().get("AddBook");
    assertTrue(addBook.getSinglepartition());
}
Also used : Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure) Catalog(org.voltdb.catalog.Catalog)

Aggregations

Catalog (org.voltdb.catalog.Catalog)44 File (java.io.File)21 Database (org.voltdb.catalog.Database)12 IOException (java.io.IOException)8 Table (org.voltdb.catalog.Table)7 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)6 CatalogContext (org.voltdb.CatalogContext)5 Procedure (org.voltdb.catalog.Procedure)5 DeploymentType (org.voltdb.compiler.deploymentfile.DeploymentType)5 DbSettings (org.voltdb.settings.DbSettings)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 TPCCProjectBuilder (org.voltdb.benchmark.tpcc.TPCCProjectBuilder)4 Cluster (org.voltdb.catalog.Cluster)4 VoltCompiler (org.voltdb.compiler.VoltCompiler)4 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)4 FileInputStream (java.io.FileInputStream)3 HostMessenger (org.voltcore.messaging.HostMessenger)3 PlannerTool (org.voltdb.compiler.PlannerTool)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2