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());
}
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;
}
}
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);
}
}
}
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()));
}
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());
}
Aggregations