Search in sources :

Example 41 with Catalog

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

the class TestVoltCompiler method testOverrideNonAnnotatedProcInfo.

public void testOverrideNonAnnotatedProcInfo() throws IOException {
    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;" + "partition procedure AddBook ON TABLE books COLUMN cash;";
    ProcInfoData info = new ProcInfoData();
    info.singlePartition = true;
    info.partitionInfo = "BOOKS.CASH: 0";
    Map<String, ProcInfoData> overrideMap = new HashMap<>();
    overrideMap.put("AddBook", info);
    VoltCompiler compiler = new VoltCompiler(false);
    compiler.setProcInfoOverrides(overrideMap);
    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 : HashMap(java.util.HashMap) ProcInfoData(org.voltdb.ProcInfoData) Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure) Catalog(org.voltdb.catalog.Catalog)

Example 42 with Catalog

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

the class TestVoltCompiler method testSnapshotSettings.

public void testSnapshotSettings() throws IOException {
    String schemaPath = "";
    try {
        URL url = TPCCProjectBuilder.class.getResource("tpcc-ddl.sql");
        schemaPath = URLDecoder.decode(url.getPath(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addProcedures(org.voltdb.compiler.procedures.TPCCTestProc.class);
    builder.setSnapshotSettings("32m", 5, "/tmp", "woobar");
    builder.addSchema(schemaPath);
    try {
        assertTrue(builder.compile("/tmp/snapshot_settings_test.jar"));
        String catalogContents = VoltCompilerUtils.readFileFromJarfile("/tmp/snapshot_settings_test.jar", "catalog.txt");
        Catalog cat = new Catalog();
        cat.execute(catalogContents);
        CatalogUtil.compileDeployment(cat, builder.getPathToDeployment(), false);
        SnapshotSchedule schedule = cat.getClusters().get("cluster").getDatabases().get("database").getSnapshotschedule().get("default");
        assertEquals(32, schedule.getFrequencyvalue());
        assertEquals("m", schedule.getFrequencyunit());
        assertEquals("woobar", schedule.getPrefix());
    } finally {
        File jar = new File("/tmp/snapshot_settings_test.jar");
        jar.delete();
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) SnapshotSchedule(org.voltdb.catalog.SnapshotSchedule) File(java.io.File) URL(java.net.URL) Catalog(org.voltdb.catalog.Catalog)

Example 43 with Catalog

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

the class TestCatalogUtil method verifyDeserializedDRTableSignature.

@SafeVarargs
private final void verifyDeserializedDRTableSignature(String schema, Pair<String, String>... signatures) throws IOException {
    String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
    final File file = VoltFile.createTempFile("deserializeCat", ".jar", new File(testDir));
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema(schema);
    builder.compile(file.getPath());
    Catalog cat = TestCatalogDiffs.catalogForJar(file.getPath());
    file.delete();
    final Map<String, String> sig = CatalogUtil.deserializeCatalogSignature(CatalogUtil.calculateDrTableSignatureAndCrc(cat.getClusters().get("cluster").getDatabases().get("database")).getSecond());
    assertEquals(signatures.length, sig.size());
    for (Pair<String, String> expected : signatures) {
        assertEquals(expected.getSecond(), sig.get(expected.getFirst()));
    }
}
Also used : VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) File(java.io.File) Catalog(org.voltdb.catalog.Catalog)

Example 44 with Catalog

use of org.voltdb.catalog.Catalog 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

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