@Test public final void testCreateTable2() throws Exception { executeString("CREATE DATABASE D1;").close(); executeString("CREATE DATABASE D2;").close(); executeString("CREATE TABLE D1.table1 (age int);").close(); executeString("CREATE TABLE D1.table2 (age int);").close(); executeString("CREATE TABLE d2.table3 (age int);").close(); executeString("CREATE TABLE d2.table4 (age int);").close(); assertTableExists("d1.table1"); assertTableExists("d1.table2"); assertTableNotExists("d2.table1"); assertTableNotExists("d2.table2"); assertTableExists("d2.table3"); assertTableExists("d2.table4"); assertTableNotExists("d1.table3"); assertTableNotExists("d1.table4"); executeString("DROP TABLE D1.table1"); executeString("DROP TABLE D1.table2"); executeString("DROP TABLE D2.table3"); executeString("DROP TABLE D2.table4"); assertDatabaseExists("d1"); assertDatabaseExists("d2"); executeString("DROP DATABASE D1").close(); executeString("DROP DATABASE D2").close(); assertDatabaseNotExists("d1"); assertDatabaseNotExists("d2"); }
@Test public final void testNestedRecord2() throws Exception { executeString("CREATE DATABASE D9;").close(); assertTableNotExists("d9.nested_table2"); executeQuery(); assertTableExists("d9.nested_table2"); executeString("DROP TABLE D9.nested_table2"); executeString("DROP DATABASE D9").close(); }
@Test public final void testCreateTableIfNotExists() throws Exception { executeString("CREATE DATABASE D3;").close(); assertTableNotExists("d3.table1"); executeString("CREATE TABLE D3.table1 (age int);").close(); assertTableExists("d3.table1"); executeString("CREATE TABLE IF NOT EXISTS D3.table1 (age int);").close(); assertTableExists("d3.table1"); executeString("DROP TABLE D3.table1"); }
@Test public final void testDropTableIfExists() throws Exception { executeString("CREATE DATABASE D7;").close(); assertTableNotExists("d7.table1"); executeString("CREATE TABLE d7.table1 (age int);").close(); assertTableExists("d7.table1"); executeString("DROP TABLE d7.table1;").close(); assertTableNotExists("d7.table1"); executeString("DROP TABLE IF EXISTS d7.table1"); assertTableNotExists("d7.table1"); executeString("DROP DATABASE D7;").close(); }
@Test public final void testCreateTable1() throws Exception { List<String> createdNames = executeDDL("table1_ddl.sql", "table1", "table1"); assertTableExists(createdNames.get(0)); executeString("DROP TABLE table1"); }
@Test public final void testCreateTableLike1() throws Exception { // //HiveCatalogStore does not support varchar type in hive-0.12.0 if (testingCluster.isHiveCatalogStoreRunning()) { // Basic create table with default database executeString("CREATE TABLE table1 (c1 int, c2 text);").close(); executeString("CREATE TABLE table2 LIKE table1"); String testMsg = "testCreateTableLike1: Basic create table with default db"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Basic create table with database executeString("CREATE DATABASE d1").close(); executeString("CREATE TABLE d1.table1 (c1 int, c2 text);").close(); executeString("CREATE TABLE d1.table2 LIKE d1.table1"); testMsg = "testCreateTableLike1: Basic create table with db test failed"; assertTrue(testMsg, isClonedTable("d1.table1", "d1.table2")); executeString("DROP TABLE d1.table1"); executeString("DROP TABLE d1.table2"); // Table with non-default store type executeString("CREATE TABLE table1 (c1 int, c2 text) USING rcfile;").close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table with non-default store type test failed"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Table with non-default meta options executeString( "CREATE TABLE table1 (c1 int, c2 text) USING text WITH ('text.delimiter'='|','compression.codec'='org.apache.hadoop.io.compress.DeflateCodec');") .close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table with non-default meta options test failed"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Table with partitions (default partition type) executeString( "CREATE TABLE table1 (c1 int, c2 text) PARTITION BY COLUMN (c3 int, c4 float, c5 text);") .close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table with partitions test failed"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Table with external flag // Use existing file as input for creating external table String className = getClass().getSimpleName(); Path currentDatasetPath = new Path(datasetBasePath, className); Path filePath = StorageUtil.concatPath(currentDatasetPath, "table1"); executeString( "CREATE EXTERNAL TABLE table3 (c1 int, c2 text) USING rcfile LOCATION '" + filePath.toUri() + "'") .close(); executeString("CREATE TABLE table2 LIKE table3"); testMsg = "testCreateTableLike1: Table with external table flag test failed"; assertTrue(testMsg, isClonedTable("table3", "table2")); executeString("DROP TABLE table3"); executeString("DROP TABLE table2"); // Table created using CTAS executeString("CREATE TABLE table3 (c1 int, c2 text) PARTITION BY COLUMN (c3 int);").close(); executeString("CREATE TABLE table4 AS SELECT c1 * c1 as m_c1, c2, c2 as c2_a,c3 from table3;") .close(); executeString("CREATE TABLE table2 LIKE table4"); testMsg = "testCreateTableLike1: Table using CTAS test failed"; assertTrue(testMsg, isClonedTable("table4", "table2")); executeString("DROP TABLE table3"); executeString("DROP TABLE table4"); executeString("DROP TABLE table2"); } else { // Basic create table with default database executeString("CREATE TABLE table1 (c1 int, c2 varchar);").close(); executeString("CREATE TABLE table2 LIKE table1"); String testMsg = "testCreateTableLike1: Basic create table with default db"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Basic create table with database executeString("CREATE DATABASE d1").close(); executeString("CREATE TABLE d1.table1 (c1 int, c2 varchar);").close(); executeString("CREATE TABLE d1.table2 LIKE d1.table1"); testMsg = "testCreateTableLike1: Basic create table with db test failed"; assertTrue(testMsg, isClonedTable("d1.table1", "d1.table2")); executeString("DROP TABLE d1.table1"); executeString("DROP TABLE d1.table2"); // Table with non-default store type executeString("CREATE TABLE table1 (c1 int, c2 varchar) USING rcfile;").close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table with non-default store type test failed"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Table with non-default meta options executeString( "CREATE TABLE table1 (c1 int, c2 varchar) USING text WITH ('text.delimiter'='|','compression.codec'='org.apache.hadoop.io.compress.DeflateCodec');") .close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table with non-default meta options test failed"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Table with partitions (default partition type) executeString( "CREATE TABLE table1 (c1 int, c2 varchar) PARTITION BY COLUMN (c3 int, c4 float, c5 text);") .close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table with partitions test failed"; assertTrue(testMsg, isClonedTable("table1", "table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); // Table with external flag // Use existing file as input for creating external table String className = getClass().getSimpleName(); Path currentDatasetPath = new Path(datasetBasePath, className); Path filePath = StorageUtil.concatPath(currentDatasetPath, "table1"); executeString( "CREATE EXTERNAL TABLE table3 (c1 int, c2 varchar) USING rcfile LOCATION '" + filePath.toUri() + "'") .close(); executeString("CREATE TABLE table2 LIKE table3"); testMsg = "testCreateTableLike1: Table with external table flag test failed"; assertTrue(testMsg, isClonedTable("table3", "table2")); executeString("DROP TABLE table3"); executeString("DROP TABLE table2"); // Table created using CTAS executeString("CREATE TABLE table3 (c1 int, c2 varchar) PARTITION BY COLUMN (c3 int);") .close(); executeString("CREATE TABLE table4 AS SELECT c1*c1, c2, c2 as c2_a,c3 from table3;").close(); executeString("CREATE TABLE table2 LIKE table4"); testMsg = "testCreateTableLike1: Table using CTAS test failed"; assertTrue(testMsg, isClonedTable("table4", "table2")); executeString("DROP TABLE table3"); executeString("DROP TABLE table4"); executeString("DROP TABLE table2"); /* Enable when view is supported // View executeString("CREATE TABLE table3 (c1 int, c2 varchar) PARTITION BY COLUMN (c3 int);").close(); executeString("CREATE VIEW table4(c1,c2,c3) AS SELECT c1*c1, c2, c2,c3 from table3;").close(); executeString("CREATE TABLE table2 LIKE table4"); testMsg = "testCreateTableLike1: Table using VIEW test failed"; assertTrue(testMsg, isClonedTable("table4","table2")); executeString("DROP TABLE table3"); executeString("DROP TABLE table4"); executeString("DROP TABLE table2"); */ /* Enable when partition type other than column is supported // Table with partitions (range partition) executeString("CREATE TABLE table1 (c1 int, c2 varchar) PARTITION BY RANGE (c1) ( PARTITION c1 VALUES LESS THAN (2), PARTITION c1 VALUES LESS THAN (5), PARTITION c1 VALUES LESS THAN (MAXVALUE) );").close(); executeString("CREATE TABLE table2 LIKE table1"); testMsg = "testCreateTableLike1: Table using non-default partition type failed"; assertTrue(testMsg, isClonedTable("table1","table2")); executeString("DROP TABLE table1"); executeString("DROP TABLE table2"); */ } }