Search in sources :

Example 56 with Database

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

the class TestVoltCompiler method testCreateTableWithGeographyType.

public void testCreateTableWithGeographyType() throws Exception {
    String ddl = "create table polygons (" + "  id integer," + "  poly geography, " + "  sized_poly0 geography(1066), " + // min allowed length
    "  sized_poly1 geography(155), " + // max allowed length
    "  sized_poly2 geography(1048576) " + ");";
    Database db = goodDDLAgainstSimpleSchema(ddl);
    assertNotNull(db);
    Table polygonsTable = db.getTables().getIgnoreCase("polygons");
    assertNotNull(polygonsTable);
    Column geographyCol = polygonsTable.getColumns().getIgnoreCase("poly");
    assertEquals(VoltType.GEOGRAPHY.getValue(), geographyCol.getType());
    assertEquals(GeographyValue.DEFAULT_LENGTH, geographyCol.getSize());
    geographyCol = polygonsTable.getColumns().getIgnoreCase("sized_poly0");
    assertEquals(VoltType.GEOGRAPHY.getValue(), geographyCol.getType());
    assertEquals(1066, geographyCol.getSize());
    geographyCol = polygonsTable.getColumns().getIgnoreCase("sized_poly1");
    assertEquals(VoltType.GEOGRAPHY.getValue(), geographyCol.getType());
    assertEquals(155, geographyCol.getSize());
    geographyCol = polygonsTable.getColumns().getIgnoreCase("sized_poly2");
    assertEquals(VoltType.GEOGRAPHY.getValue(), geographyCol.getType());
    assertEquals(1048576, geographyCol.getSize());
}
Also used : Table(org.voltdb.catalog.Table) Column(org.voltdb.catalog.Column) Database(org.voltdb.catalog.Database)

Example 57 with Database

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

the class TestVoltCompiler method testDropRole.

public void testDropRole() throws Exception {
    Database db = goodDDLAgainstSimpleSchema("create role r1;", "drop role r1;");
    CatalogMap<Group> groups = db.getGroups();
    assertTrue(groups.get("r1") == null);
    db = goodDDLAgainstSimpleSchema("create role r1;", "drop role r1 if exists;");
    groups = db.getGroups();
    assertTrue(groups.get("r1") == null);
    db = goodDDLAgainstSimpleSchema("create role r1;", "drop role r1 if exists;", "drop role r1 IF EXISTS;");
    groups = db.getGroups();
    assertTrue(groups.get("r1") == null);
    badDDLAgainstSimpleSchema(".*does not exist.*", "create role r1;", "drop role r2;");
    badDDLAgainstSimpleSchema(".*does not exist.*", "create role r1;", "drop role r1;", "drop role r1;");
    badDDLAgainstSimpleSchema(".*may not drop.*", "drop role administrator;");
    badDDLAgainstSimpleSchema(".*may not drop.*", "drop role user;");
}
Also used : Group(org.voltdb.catalog.Group) Database(org.voltdb.catalog.Database)

Example 58 with Database

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

the class TestVoltCompilerAlterDropTable method verifyTableColumnExists.

//Check given col does exists
private void verifyTableColumnExists(VoltCompiler compiler, String tableName, String colName) {
    Database db = compiler.m_catalog.getClusters().get("cluster").getDatabases().get("database");
    Table table = db.getTables().get(tableName);
    Column col = table.getColumns().get(colName);
    assertNotNull(col);
}
Also used : Table(org.voltdb.catalog.Table) Column(org.voltdb.catalog.Column) Database(org.voltdb.catalog.Database)

Example 59 with Database

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

the class TestCatalogUtil method testSecurityProvider.

public void testSecurityProvider() throws Exception {
    final String secOff = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "   <cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + "   <paths><voltdbroot path=\"/tmp/" + System.getProperty("user.name") + "\" /></paths>" + "   <security enabled=\"true\"/>" + "   <users>" + "      <user name=\"joe\" password=\"aaa\" roles=\"administrator\"/>" + "   </users>" + "</deployment>";
    final String secOn = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "   <cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + "   <paths><voltdbroot path=\"/tmp/" + System.getProperty("user.name") + "\" /></paths>" + "   <security enabled=\"true\" provider=\"kerberos\"/>" + "   <users>" + "      <user name=\"joe\" password=\"aaa\" roles=\"administrator\"/>" + "   </users>" + "</deployment>";
    final File tmpSecOff = VoltProjectBuilder.writeStringToTempFile(secOff);
    CatalogUtil.compileDeployment(catalog, tmpSecOff.getPath(), false);
    Cluster cluster = catalog.getClusters().get("cluster");
    Database db = cluster.getDatabases().get("database");
    assertTrue(cluster.getSecurityenabled());
    assertEquals("hash", db.getSecurityprovider());
    setUp();
    final File tmpSecOn = VoltProjectBuilder.writeStringToTempFile(secOn);
    CatalogUtil.compileDeployment(catalog, tmpSecOn.getPath(), false);
    cluster = catalog.getClusters().get("cluster");
    db = cluster.getDatabases().get("database");
    assertTrue(cluster.getSecurityenabled());
    assertEquals("kerberos", db.getSecurityprovider());
}
Also used : Database(org.voltdb.catalog.Database) Cluster(org.voltdb.catalog.Cluster) File(java.io.File)

Example 60 with Database

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

the class StatementCompiler method compileDefaultProcedure.

/**
     * This procedure compiles a shim org.voltdb.catalog.Procedure representing a default proc.
     * The shim has no plan and few details that are expensive to compute.
     * The returned proc instance has a full plan and can be used to create a ProcedureRunner.
     * Note that while there are two procedure objects here, none are rooted in a real catalog;
     * they are entirely parallel to regular, catalog procs.
     *
     * This code could probably go a few different places. It duplicates a bit too much of the
     * StatmentCompiler code for my taste, so I put it here. Next pass could reduce some of the
     * duplication?
     */
public static Procedure compileDefaultProcedure(PlannerTool plannerTool, Procedure catProc, String sqlText) {
    // fake db makes it easy to create procedures that aren't part of the main catalog
    Database fakeDb = new Catalog().getClusters().add("cluster").getDatabases().add("database");
    Table table = catProc.getPartitiontable();
    // determine the type of the query
    QueryType qtype = QueryType.getFromSQL(sqlText);
    StatementPartitioning partitioning = catProc.getSinglepartition() ? StatementPartitioning.forceSP() : StatementPartitioning.forceMP();
    CompiledPlan plan = plannerTool.planSqlCore(sqlText, partitioning);
    Procedure newCatProc = fakeDb.getProcedures().add(catProc.getTypeName());
    newCatProc.setClassname(catProc.getClassname());
    newCatProc.setDefaultproc(true);
    newCatProc.setEverysite(false);
    newCatProc.setHasjava(false);
    newCatProc.setPartitioncolumn(catProc.getPartitioncolumn());
    newCatProc.setPartitionparameter(catProc.getPartitionparameter());
    newCatProc.setPartitiontable(catProc.getPartitiontable());
    newCatProc.setReadonly(catProc.getReadonly());
    newCatProc.setSinglepartition(catProc.getSinglepartition());
    newCatProc.setSystemproc(false);
    if (catProc.getPartitionparameter() >= 0) {
        newCatProc.setAttachment(new ProcedurePartitionInfo(VoltType.get((byte) catProc.getPartitioncolumn().getType()), catProc.getPartitionparameter()));
    }
    CatalogMap<Statement> statements = newCatProc.getStatements();
    assert (statements != null);
    Statement stmt = statements.add(VoltDB.ANON_STMT_NAME);
    stmt.setSqltext(sqlText);
    stmt.setReadonly(catProc.getReadonly());
    stmt.setQuerytype(qtype.getValue());
    stmt.setSinglepartition(catProc.getSinglepartition());
    stmt.setIscontentdeterministic(true);
    stmt.setIsorderdeterministic(true);
    stmt.setNondeterminismdetail("NO CONTENT FOR DEFAULT PROCS");
    stmt.setSeqscancount(plan.countSeqScans());
    stmt.setReplicatedtabledml(!catProc.getReadonly() && table.getIsreplicated());
    // We will need to update the system catalogs with this new information
    for (int i = 0; i < plan.parameters.length; ++i) {
        StmtParameter catalogParam = stmt.getParameters().add(String.valueOf(i));
        catalogParam.setIndex(i);
        ParameterValueExpression pve = plan.parameters[i];
        catalogParam.setJavatype(pve.getValueType().getValue());
        catalogParam.setIsarray(pve.getParamIsVector());
    }
    PlanFragment frag = stmt.getFragments().add("0");
    // compute a hash of the plan
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        assert (false);
        // should never happen with healthy jvm
        System.exit(-1);
    }
    byte[] planBytes = writePlanBytes(frag, plan.rootPlanGraph);
    md.update(planBytes, 0, planBytes.length);
    // compute the 40 bytes of hex from the 20 byte sha1 hash of the plans
    md.reset();
    md.update(planBytes);
    frag.setPlanhash(Encoder.hexEncode(md.digest()));
    if (plan.subPlanGraph != null) {
        frag.setHasdependencies(true);
        frag.setNontransactional(true);
        frag.setMultipartition(true);
        frag = stmt.getFragments().add("1");
        frag.setHasdependencies(false);
        frag.setNontransactional(false);
        frag.setMultipartition(true);
        byte[] subBytes = writePlanBytes(frag, plan.subPlanGraph);
        // compute the 40 bytes of hex from the 20 byte sha1 hash of the plans
        md.reset();
        md.update(subBytes);
        frag.setPlanhash(Encoder.hexEncode(md.digest()));
    } else {
        frag.setHasdependencies(false);
        frag.setNontransactional(false);
        frag.setMultipartition(false);
    }
    // set the procedure parameter types from the statement parameter types
    int paramCount = 0;
    for (StmtParameter stmtParam : CatalogUtil.getSortedCatalogItems(stmt.getParameters(), "index")) {
        // name each parameter "param1", "param2", etc...
        ProcParameter procParam = newCatProc.getParameters().add("param" + String.valueOf(paramCount));
        procParam.setIndex(stmtParam.getIndex());
        procParam.setIsarray(stmtParam.getIsarray());
        procParam.setType(stmtParam.getJavatype());
        paramCount++;
    }
    return newCatProc;
}
Also used : CompiledPlan(org.voltdb.planner.CompiledPlan) ProcedurePartitionInfo(org.voltdb.CatalogContext.ProcedurePartitionInfo) Table(org.voltdb.catalog.Table) Statement(org.voltdb.catalog.Statement) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Catalog(org.voltdb.catalog.Catalog) PlanFragment(org.voltdb.catalog.PlanFragment) StmtParameter(org.voltdb.catalog.StmtParameter) Database(org.voltdb.catalog.Database) StatementPartitioning(org.voltdb.planner.StatementPartitioning) Procedure(org.voltdb.catalog.Procedure) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression) MessageDigest(java.security.MessageDigest) QueryType(org.voltdb.types.QueryType) ProcParameter(org.voltdb.catalog.ProcParameter)

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