Search in sources :

Example 46 with Database

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

the class CatalogUtil method getNormalTableNamesFromInMemoryJar.

/**
     * Get all normal table names from a in-memory catalog jar file.
     * A normal table is one that's NOT a materialized view, nor an export table.
     * @param InMemoryJarfile a in-memory catalog jar file
     * @return A set of normal table names
     */
public static Set<String> getNormalTableNamesFromInMemoryJar(InMemoryJarfile jarfile) {
    Set<String> tableNames = new HashSet<>();
    Catalog catalog = new Catalog();
    catalog.execute(getSerializedCatalogStringFromJar(jarfile));
    Database db = catalog.getClusters().get("cluster").getDatabases().get("database");
    for (Table table : getNormalTables(db, true)) {
        tableNames.add(table.getTypeName());
    }
    for (Table table : getNormalTables(db, false)) {
        tableNames.add(table.getTypeName());
    }
    return tableNames;
}
Also used : VoltTable(org.voltdb.VoltTable) Table(org.voltdb.catalog.Table) Database(org.voltdb.catalog.Database) SystemProcedureCatalog(org.voltdb.SystemProcedureCatalog) Catalog(org.voltdb.catalog.Catalog) HashSet(java.util.HashSet)

Example 47 with Database

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

the class TestVoltCompiler method testGoodCreateProcedureWithAllow.

public void testGoodCreateProcedureWithAllow() throws Exception {
    Database db = goodDDLAgainstSimpleSchema("create role r1;", "create procedure p1 allow r1 as select * from books;");
    Procedure proc = db.getProcedures().get("p1");
    assertNotNull(proc);
    CatalogMap<GroupRef> groups = proc.getAuthgroups();
    assertEquals(1, groups.size());
    assertNotNull(groups.get("r1"));
    db = goodDDLAgainstSimpleSchema("create role r1;", "create role r2;", "create procedure p1 allow r1, r2 as select * from books;");
    proc = db.getProcedures().get("p1");
    assertNotNull(proc);
    groups = proc.getAuthgroups();
    assertEquals(2, groups.size());
    assertNotNull(groups.get("r1"));
    assertNotNull(groups.get("r2"));
    db = goodDDLAgainstSimpleSchema("create role r1;", "create procedure allow r1 from class org.voltdb.compiler.procedures.AddBook;");
    proc = db.getProcedures().get("AddBook");
    assertNotNull(proc);
    groups = proc.getAuthgroups();
    assertEquals(1, groups.size());
    assertNotNull(groups.get("r1"));
    db = goodDDLAgainstSimpleSchema("create role r1;", "create role r2;", "create procedure allow r1,r2 from class org.voltdb.compiler.procedures.AddBook;");
    proc = db.getProcedures().get("AddBook");
    assertNotNull(proc);
    groups = proc.getAuthgroups();
    assertEquals(2, groups.size());
    assertNotNull(groups.get("r1"));
    assertNotNull(groups.get("r2"));
    db = goodDDLAgainstSimpleSchema("create role r1;", "create procedure allow r1,r1 from class org.voltdb.compiler.procedures.AddBook;");
    proc = db.getProcedures().get("AddBook");
    assertNotNull(proc);
    groups = proc.getAuthgroups();
    assertEquals(1, groups.size());
    assertNotNull(groups.get("r1"));
}
Also used : Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure) GroupRef(org.voltdb.catalog.GroupRef)

Example 48 with Database

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

the class TestVoltCompiler method testGoodDropStream.

public void testGoodDropStream() throws Exception {
    Database db;
    db = goodDDLAgainstSimpleSchema(// drop an independent stream
    "CREATE STREAM e1 (D1 INTEGER, D2 INTEGER, D3 INTEGER, VAL1 INTEGER, VAL2 INTEGER, VAL3 INTEGER);\n" + "DROP STREAM e1;\n", // try drop an non-existent stream
    "DROP STREAM e2 IF EXISTS;\n", //  automatically drop reference views for the stream
    "CREATE STREAM User_Stream Partition On Column UserId" + " (UserId BIGINT NOT NULL, SessionStart TIMESTAMP);\n" + "CREATE VIEW User_Logins (UserId, LoginCount)" + " AS SELECT UserId, Count(*) FROM User_Stream GROUP BY UserId;\n" + "CREATE VIEW User_LoginLastTime (UserId, LoginCount, LoginLastTime)" + " AS SELECT UserId, Count(*), MAX(SessionStart) FROM User_Stream GROUP BY UserId;\n" + "DROP STREAM User_Stream IF EXISTS CASCADE ;\n");
    assertNull(getTableInfoFor(db, "e1"));
    assertNull(getTableInfoFor(db, "e2"));
    assertNull(getTableInfoFor(db, "User_Stream"));
    assertNull(getTableInfoFor(db, "User_Logins"));
    assertNull(getTableInfoFor(db, "User_LoginLastTime"));
}
Also used : Database(org.voltdb.catalog.Database)

Example 49 with Database

use of org.voltdb.catalog.Database 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 50 with Database

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

the class TestVoltCompiler method testDropProcedure.

public void testDropProcedure() throws Exception {
    if (Float.parseFloat(System.getProperty("java.specification.version")) < 1.7) {
        return;
    }
    Database db;
    Procedure proc;
    // Make sure we can drop a non-annotated stored procedure
    db = goodDDLAgainstSimpleSchema("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook; " + "create procedure from class org.voltdb.compiler.procedures.NotAnnotatedAddBook; " + "DROP PROCEDURE org.voltdb.compiler.procedures.AddBook;");
    proc = db.getProcedures().get("AddBook");
    assertNull(proc);
    proc = db.getProcedures().get("NotAnnotatedAddBook");
    assertNotNull(proc);
    // Make sure we can drop an annotated stored procedure
    db = goodDDLAgainstSimpleSchema("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook; " + "create procedure from class org.voltdb.compiler.procedures.NotAnnotatedAddBook; " + "DROP PROCEDURE NotAnnotatedAddBook;");
    proc = db.getProcedures().get("NotAnnotatedAddBook");
    assertNull(proc);
    proc = db.getProcedures().get("AddBook");
    assertNotNull(proc);
    // Make sure we can drop a single-statement procedure
    db = goodDDLAgainstSimpleSchema("create procedure p1 as select * from books;\n" + "drop procedure p1;");
    proc = db.getProcedures().get("p1");
    assertNull(proc);
    ArrayList<Feedback> fbs = checkInvalidDDL("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook; " + "DROP PROCEDURE NotAnnotatedAddBook;");
    String expectedError = "Dropped Procedure \"NotAnnotatedAddBook\" is not defined";
    assertTrue(isFeedbackPresent(expectedError, fbs));
    // Make sure we can't drop a CRUD procedure (full name)
    fbs = checkInvalidDDL("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "DROP PROCEDURE PKEY_INTEGER.insert;");
    expectedError = "Dropped Procedure \"PKEY_INTEGER.insert\" is not defined";
    assertTrue(isFeedbackPresent(expectedError, fbs));
    // Make sure we can't drop a CRUD procedure (partial name)
    fbs = checkInvalidDDL("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "DROP PROCEDURE insert;");
    expectedError = "Dropped Procedure \"insert\" is not defined";
    assertTrue(isFeedbackPresent(expectedError, fbs));
    // check if exists
    db = goodDDLAgainstSimpleSchema("create procedure p1 as select * from books;\n" + "drop procedure p1 if exists;\n" + "drop procedure p1 if exists;\n");
    proc = db.getProcedures().get("p1");
    assertNull(proc);
}
Also used : Feedback(org.voltdb.compiler.VoltCompiler.Feedback) Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure)

Aggregations

Database (org.voltdb.catalog.Database)62 Table (org.voltdb.catalog.Table)22 Catalog (org.voltdb.catalog.Catalog)12 Cluster (org.voltdb.catalog.Cluster)10 File (java.io.File)9 Column (org.voltdb.catalog.Column)9 Procedure (org.voltdb.catalog.Procedure)9 IOException (java.io.IOException)5 VoltTable (org.voltdb.VoltTable)5 ArrayList (java.util.ArrayList)4 Group (org.voltdb.catalog.Group)4 Connector (org.voltdb.catalog.Connector)3 Constraint (org.voltdb.catalog.Constraint)3 Statement (org.voltdb.catalog.Statement)3 FileNotFoundException (java.io.FileNotFoundException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 JAXBException (javax.xml.bind.JAXBException)2