Search in sources :

Example 6 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestJdbcDatabaseMetaDataGenerator method testGetClasses.

public void testGetClasses() throws Exception {
    String schema = "create table Table1 (Column1 varchar(200) not null, Column2 integer);" + "partition table Table1 on column Column1;" + "create procedure proc1 as select * from Table1 where Column1=?;" + "partition procedure proc1 on table Table1 column Column1;" + "create procedure proc2 as select * from Table1 where Column2=?;" + "import class org.voltdb_testprocs.fullddlfeatures.*;" + "create procedure from class org.voltdb_testprocs.fullddlfeatures.testImportProc;";
    VoltCompiler c = compileForDDLTest2(schema);
    JdbcDatabaseMetaDataGenerator dut = new JdbcDatabaseMetaDataGenerator(c.getCatalog(), null, new InMemoryJarfile(testout_jar));
    VoltTable classes = dut.getMetaData("classes");
    System.out.println(classes);
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(classes, "CLASS_NAME", "org.voltdb_testprocs.fullddlfeatures.testImportProc"));
    assertEquals(1, classes.get("VOLT_PROCEDURE", VoltType.INTEGER));
    assertEquals(1, classes.get("ACTIVE_PROC", VoltType.INTEGER));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(classes, "CLASS_NAME", "org.voltdb_testprocs.fullddlfeatures.testCreateProcFromClassProc"));
    assertEquals(1, classes.get("VOLT_PROCEDURE", VoltType.INTEGER));
    assertEquals(0, classes.get("ACTIVE_PROC", VoltType.INTEGER));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(classes, "CLASS_NAME", "org.voltdb_testprocs.fullddlfeatures.NoMeaningClass"));
    assertEquals(0, classes.get("VOLT_PROCEDURE", VoltType.INTEGER));
    assertEquals(0, classes.get("ACTIVE_PROC", VoltType.INTEGER));
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

Example 7 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestJdbcDatabaseMetaDataGenerator method testGetIndexInfo.

public void testGetIndexInfo() throws Exception {
    String schema = "create table Table1 (Column1 smallint ASSUMEUNIQUE, Column2 integer, Column3 bigint not null, Column4 integer, Column5 integer, " + "  constraint pk_tree primary key (Column1, Column3));" + "partition table Table1 on column Column3;" + "create index Index1_tree on Table1 (Column2, Column3);" + "create index Index2_hash on Table1 (Column4, Column5);" + "create procedure sample as select * from Table1;";
    VoltCompiler c = compileForDDLTest2(schema);
    System.out.println(c.getCatalog().serialize());
    JdbcDatabaseMetaDataGenerator dut = new JdbcDatabaseMetaDataGenerator(c.getCatalog(), null, new InMemoryJarfile(testout_jar));
    VoltTable indexes = dut.getMetaData("IndexInfo");
    System.out.println(indexes);
    assertEquals(13, indexes.getColumnCount());
    assertEquals(7, indexes.getRowCount());
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", "INDEX1_TREE", "COLUMN_NAME", "Column2"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 1, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexOther, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 1, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals("A", indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", "INDEX1_TREE", "COLUMN_NAME", "Column3"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 1, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexOther, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 2, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals("A", indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", "INDEX2_HASH", "COLUMN_NAME", "Column4"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 1, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexHashed, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 1, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals(null, indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", "INDEX2_HASH", "COLUMN_NAME", "Column5"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 1, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexHashed, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 2, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals(null, indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", HSQLInterface.AUTO_GEN_NAMED_CONSTRAINT_IDX + "PK_TREE", "COLUMN_NAME", "Column1"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 0, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexOther, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 1, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals("A", indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", HSQLInterface.AUTO_GEN_NAMED_CONSTRAINT_IDX + "PK_TREE", "COLUMN_NAME", "Column3"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 0, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexOther, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 2, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals("A", indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingTupleRow(indexes, "INDEX_NAME", HSQLInterface.AUTO_GEN_UNIQUE_IDX_PREFIX + "TABLE1_COLUMN1", "COLUMN_NAME", "Column1"));
    assertEquals("TABLE1", indexes.get("TABLE_NAME", VoltType.STRING));
    assertEquals((byte) 0, indexes.get("NON_UNIQUE", VoltType.TINYINT));
    assertEquals(java.sql.DatabaseMetaData.tableIndexOther, indexes.get("TYPE", VoltType.SMALLINT));
    assertEquals((short) 1, indexes.get("ORDINAL_POSITION", VoltType.SMALLINT));
    assertEquals("A", indexes.get("ASC_OR_DESC", VoltType.STRING));
    assertFalse(VoltTableTestHelpers.moveToMatchingRow(indexes, "COLUMN_NAME", "NotAColumn"));
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

Example 8 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestJdbcDatabaseMetaDataGenerator method testGetTypeInfo.

public void testGetTypeInfo() throws Exception {
    String schema = "create table Table1 (Column1 varchar(200) not null, Column2 integer);" + "partition table Table1 on column Column1;" + "create procedure proc1 as select * from Table1 where Column1=?;" + "partition procedure proc1 on table Table1 column Column1;" + "create procedure proc2 as select * from Table1 where Column2=?;";
    VoltCompiler c = compileForDDLTest2(schema);
    JdbcDatabaseMetaDataGenerator dut = new JdbcDatabaseMetaDataGenerator(c.getCatalog(), null, new InMemoryJarfile(testout_jar));
    VoltTable typeInfo = dut.getMetaData("typEINfo");
    System.out.println(typeInfo);
    // just do some minor sanity checks on size of table and that it contains the types
    // we expect
    HashMap<String, VoltType> expectedTypes = new HashMap<String, VoltType>();
    for (VoltType type : VoltType.values()) {
        if (type.isJdbcVisible()) {
            expectedTypes.put(type.toSQLString().toUpperCase(), type);
        }
    }
    assertEquals(expectedTypes.size(), typeInfo.getRowCount());
    assertEquals(18, typeInfo.getColumnCount());
    typeInfo.resetRowPosition();
    while (typeInfo.advanceRow()) {
        String gotName = typeInfo.getString("TYPE_NAME");
        VoltType expectedType = expectedTypes.remove(gotName);
        assertTrue(expectedType != null);
    }
    assertTrue(expectedTypes.isEmpty());
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) HashMap(java.util.HashMap) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

Example 9 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestJdbcDatabaseMetaDataGenerator method testGetProcedureColumns.

public void testGetProcedureColumns() throws Exception {
    String schema = "create table Table1 (Column1 varchar(200) not null, Column2 integer);" + "partition table Table1 on column Column1;" + "create procedure proc1 as select * from Table1 where Column1=?;" + "partition procedure proc1 on table Table1 column Column1;" + "create procedure proc2 as select * from Table1 where Column2=?;";
    VoltCompiler c = compileForDDLTest2(schema);
    System.out.println(c.getCatalog().serialize());
    DefaultProcedureManager defaultProcs = new DefaultProcedureManager(c.getCatalogDatabase());
    JdbcDatabaseMetaDataGenerator dut = new JdbcDatabaseMetaDataGenerator(c.getCatalog(), defaultProcs, new InMemoryJarfile(testout_jar));
    VoltTable params = dut.getMetaData("ProcedureColumns");
    System.out.println(params);
    assertEquals(20, params.getColumnCount());
    // 2 real and 2 crud inserts
    assertEquals(4, params.getRowCount());
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(params, "PROCEDURE_NAME", "proc1"));
    assertEquals("param0", params.get("COLUMN_NAME", VoltType.STRING));
    assertEquals(VoltType.MAX_VALUE_LENGTH, params.get("PRECISION", VoltType.INTEGER));
    assertEquals(VoltType.MAX_VALUE_LENGTH, params.get("LENGTH", VoltType.INTEGER));
    assertEquals(VoltType.MAX_VALUE_LENGTH, params.get("CHAR_OCTET_LENGTH", VoltType.INTEGER));
    assertEquals("PARTITION_PARAMETER", params.get("REMARKS", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(params, "PROCEDURE_NAME", "proc2"));
    assertEquals("param0", params.get("COLUMN_NAME", VoltType.STRING));
    assertEquals(VoltType.INTEGER.getLengthInBytesForFixedTypes() * 8 - 1, params.get("PRECISION", VoltType.INTEGER));
    assertEquals(VoltType.INTEGER.getLengthInBytesForFixedTypes(), params.get("LENGTH", VoltType.INTEGER));
    assertWithNullCheck(null, params.get("CHAR_OCTET_LENGTH", VoltType.INTEGER), params);
    assertWithNullCheck(null, params.get("REMARKS", VoltType.STRING), params);
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

Example 10 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestCatalogVersionUpgrade method testCatalogAutoUpgradeFail.

public void testCatalogAutoUpgradeFail() throws Exception {
    TPCCProjectBuilder project = new TPCCProjectBuilder();
    project.addDefaultSchema();
    project.addDefaultPartitioning();
    project.addDefaultProcedures();
    String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
    String jarName = "compile-deployment.jar";
    String catalogJar = testDir + File.separator + jarName;
    assertTrue("Project failed to compile", project.compile(catalogJar));
    // Load the catalog to an in-memory jar and tweak the version to make it incompatible.
    byte[] bytes = MiscUtils.fileToBytes(new File(catalogJar));
    InMemoryJarfile memCatalog = CatalogUpgradeTools.loadCatalog(bytes, false);
    CatalogUpgradeTools.dorkVersion(memCatalog);
    // Squizzle creation is no longer supported.
    CatalogUpgradeTools.dorkDDL(memCatalog, "CREATE SQUIZZLE");
    // Check the (hopefully) upgraded catalog version against the server version.
    try {
        CatalogUpgradeTools.loadCatalog(memCatalog.getFullJarBytes(), true);
        fail("Expected load to generate an exception");
    } catch (IOException e) {
        // Happy if the message mentions the bad create statement.
        String message = e.getMessage();
        assertTrue(message.contains(UPGRADE_ERROR_MESSAGE_SUBSTRING));
    }
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) IOException(java.io.IOException) TPCCProjectBuilder(org.voltdb.benchmark.tpcc.TPCCProjectBuilder) File(java.io.File)

Aggregations

InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)52 VoltCompiler (org.voltdb.compiler.VoltCompiler)26 File (java.io.File)20 ProcCallException (org.voltdb.client.ProcCallException)19 ClientResponse (org.voltdb.client.ClientResponse)18 Test (org.junit.Test)15 Configuration (org.voltdb.VoltDB.Configuration)15 IOException (java.io.IOException)14 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)12 VoltDB (org.voltdb.VoltDB)9 Catalog (org.voltdb.catalog.Catalog)6 VoltTable (org.voltdb.VoltTable)5 VoltFile (org.voltdb.utils.VoltFile)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json_voltpatches.JSONObject)3 CatalogContext (org.voltdb.CatalogContext)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JAXBException (javax.xml.bind.JAXBException)2