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)); }
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()); assertEquals(4, params.getRowCount()); // 2 real and 2 crud inserts 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); }
public void testGetPrimaryKeys() throws Exception { String schema = "create table Table1 (Column1 smallint not null, constraint primary1 primary key (Column1));" + "partition table Table1 on column Column1;" + "create table Table2 (Column2 smallint not null, Column3 smallint not null, Column4 smallint not null, " + " constraint primary2 primary key (Column2, Column3, Column4));" + "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 pkeys = dut.getMetaData("PrimaryKeys"); System.out.println(pkeys); assertEquals(6, pkeys.getColumnCount()); assertEquals(4, pkeys.getRowCount()); assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column1")); assertEquals("TABLE1", pkeys.get("TABLE_NAME", VoltType.STRING)); assertEquals((short) 1, pkeys.get("KEY_SEQ", VoltType.SMALLINT)); assertEquals("PRIMARY1", pkeys.get("PK_NAME", VoltType.STRING)); assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column2")); assertEquals("TABLE2", pkeys.get("TABLE_NAME", VoltType.STRING)); assertEquals((short) 1, pkeys.get("KEY_SEQ", VoltType.SMALLINT)); assertEquals("PRIMARY2", pkeys.get("PK_NAME", VoltType.STRING)); assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column3")); assertEquals("TABLE2", pkeys.get("TABLE_NAME", VoltType.STRING)); assertEquals((short) 2, pkeys.get("KEY_SEQ", VoltType.SMALLINT)); assertEquals("PRIMARY2", pkeys.get("PK_NAME", VoltType.STRING)); assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column4")); assertEquals("TABLE2", pkeys.get("TABLE_NAME", VoltType.STRING)); assertEquals((short) 3, pkeys.get("KEY_SEQ", VoltType.SMALLINT)); assertEquals("PRIMARY2", pkeys.get("PK_NAME", VoltType.STRING)); }
private void verifyColumnData(String columnName, VoltTable columns, Object[] expected) { assertTrue(VoltTableTestHelpers.moveToMatchingRow(columns, "COLUMN_NAME", columnName)); assertEquals(expected[0], columns.get("DATA_TYPE", VoltType.INTEGER)); assertTrue( "SQL Typename mismatch", columns.get("TYPE_NAME", VoltType.STRING).equals(expected[1])); assertWithNullCheck(expected[2], columns.get("COLUMN_SIZE", VoltType.INTEGER), columns); assertWithNullCheck(expected[3], columns.get("DECIMAL_DIGITS", VoltType.INTEGER), columns); assertWithNullCheck(expected[4], columns.get("NUM_PREC_RADIX", VoltType.INTEGER), columns); assertEquals( "Null mismatch for column " + columnName, expected[5], columns.get("NULLABLE", VoltType.INTEGER)); assertWithNullCheck(expected[6], columns.get("REMARKS", VoltType.STRING), columns); assertWithNullCheck(expected[7], columns.get("COLUMN_DEF", VoltType.STRING), columns); assertWithNullCheck(expected[8], columns.get("CHAR_OCTET_LENGTH", VoltType.INTEGER), columns); assertEquals(expected[9], columns.get("ORDINAL_POSITION", VoltType.INTEGER)); }
public void testGetTables() throws Exception { String schema = "create table Table1 (Column1 varchar(10) not null, Column2 integer);" + "partition table Table1 on column Column1;" + "create table Table2 (Column1 integer);" + "create view View1 (Column1, num) as select Column1, count(*) from Table1 group by Column1;" + "create view View2 (Column2, num) as select Column2, count(*) from Table1 group by Column2;" + "create table Export1 (Column1 integer);" + "export table Export1;" + "create table Export2 (Column1 integer);" + "export table Export2 to stream foo;" + "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 tables = dut.getMetaData("tables"); System.out.println(tables); assertEquals(10, tables.getColumnCount()); assertEquals(6, tables.getRowCount()); assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Table1")); assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("TABLE")); assertTrue(tables.get("REMARKS", VoltType.STRING).equals("{\"partitionColumn\":\"COLUMN1\"}")); assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Table2")); assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("TABLE")); assertEquals(null, tables.get("REMARKS", VoltType.STRING)); assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "View1")); assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("VIEW")); assertTrue( tables .get("REMARKS", VoltType.STRING) .equals( new JSONObject("{\"partitionColumn\":\"COLUMN1\",\"sourceTable\":\"TABLE1\"}") .toString())); assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "View2")); assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("VIEW")); assertTrue( tables .get("REMARKS", VoltType.STRING) .equals( new JSONObject("{\"partitionColumn\":\"COLUMN1\",\"sourceTable\":\"TABLE1\"}") .toString())); assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Export1")); assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("EXPORT")); assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Export2")); assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("EXPORT")); assertFalse(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "NotATable")); }
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_CONSTRAINT_WRAPPER_PREFIX + "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_CONSTRAINT_WRAPPER_PREFIX + "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_CONSTRAINT_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")); }