Skip to content

Commit

Permalink
Use plain String concatenation for test setup (#57)
Browse files Browse the repository at this point in the history
* Use plain String concatenation for test setup

This allows easy copying from IDE into e.g. `beeline`.

* Update a comment
  • Loading branch information
findepi authored Mar 18, 2021
1 parent fb042eb commit 89460e8
Showing 1 changed file with 66 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,74 +186,73 @@ public static void initializeViews() throws HiveException, MetaException {
HiveMetastoreClient hiveMetastoreClient = new HiveMscAdapter(Hive.get(conf).getMSC());
hiveToRelConverter = HiveToRelConverter.create(hiveMetastoreClient);

// Views and tables used in FuzzyUnionViewTest
run(driver, String.join("\n", "CREATE DATABASE IF NOT EXISTS test"));

run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableA(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view AS ",
"SELECT * from test.tableA union all SELECT * from test.tableA"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_with_more_than_two_tables AS ",
"SELECT * from test.tableA union all SELECT * from test.tableA union all SELECT * from test.tableA"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_with_alias AS ",
"SELECT * FROM (SELECT * from test.tableA) as viewFirst union all SELECT * FROM (SELECT * from test.tableA) as viewSecond"));

run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableB(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableC(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_single_branch_evolved AS ",
"SELECT * from test.tableB union all SELECT * from test.tableC"));
run(driver, String.join("\n", "ALTER TABLE test.tableC CHANGE COLUMN b b struct<b1:string, b2:int>"));

run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableD(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableE(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_double_branch_evolved_same AS ",
"SELECT * from test.tableD union all SELECT * from test.tableE"));
run(driver, String.join("\n", "ALTER TABLE test.tableD CHANGE COLUMN b b struct<b1:string, b2:int>"));
run(driver, String.join("\n", "ALTER TABLE test.tableE CHANGE COLUMN b b struct<b1:string, b2:int>"));

run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableF(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableG(a int, b struct<b1:string>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_double_branch_evolved_different AS ",
"SELECT * from test.tableF union all SELECT * from test.tableG"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_more_than_two_branches_evolved AS ",
"SELECT * from test.tableF union all SELECT * from test.tableG union all SELECT * from test.tableF"));
run(driver, String.join("\n", "ALTER TABLE test.tableF CHANGE COLUMN b b struct<b1:string, b3:string>"));
run(driver, String.join("\n", "ALTER TABLE test.tableG CHANGE COLUMN b b struct<b1:string, b2:int>"));

run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableH(a int, b map<string, struct<b1:string>>)"));
run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableI(a int, b map<string, struct<b1:string>>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_map_with_struct_value_evolved AS ",
"SELECT * from test.tableH union all SELECT * from test.tableI"));
run(driver, String.join("\n", "ALTER TABLE test.tableH CHANGE COLUMN b b map<string, struct<b1:string, b2:int>>"));

run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableJ(a int, b array<struct<b1:string>>)"));
run(driver, String.join("\n", "CREATE TABLE IF NOT EXISTS test.tableK(a int, b array<struct<b1:string>>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_array_with_struct_value_evolved AS ",
"SELECT * from test.tableJ union all SELECT * from test.tableK"));
run(driver, String.join("\n", "ALTER TABLE test.tableJ CHANGE COLUMN b b array<struct<b1:string, b2:int>>"));

run(driver, String.join("\n",
"CREATE TABLE IF NOT EXISTS test.tableL(a int, b struct<b1:string, b2:struct<b3:string, b4:struct<b5:string>>>)"));
run(driver, String.join("\n",
"CREATE TABLE IF NOT EXISTS test.tableM(a int, b struct<b1:string, b2:struct<b3:string, b4:struct<b5:string>>>)"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_deeply_nested_struct_evolved AS ",
"SELECT * from test.tableL union all SELECT * from test.tableM"));
run(driver, String.join("\n",
"ALTER TABLE test.tableL CHANGE COLUMN b b struct<b1:string, b2:struct<b3:string, b4:struct<b5:string, b6:string>>>"));

run(driver, String.join("\n",
"CREATE TABLE IF NOT EXISTS test.tableN(a int, b struct<b1:string, m1:map<string, struct<b1:string, a1:array<struct<b1:string>>>>>)"));
run(driver, String.join("\n",
"CREATE TABLE IF NOT EXISTS test.tableO(a int, b struct<b1:string, m1:map<string, struct<b1:string, a1:array<struct<b1:string>>>>>)"));
// Views and tables used in HiveToPrestoConverterTest
run(driver, "CREATE DATABASE IF NOT EXISTS test");

run(driver, "CREATE TABLE IF NOT EXISTS test.tableA(a int, b struct<b1:string>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view AS \n"
+ "SELECT * from test.tableA union all SELECT * from test.tableA");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_with_more_than_two_tables AS \n"
+ "SELECT * from test.tableA union all SELECT * from test.tableA union all SELECT * from test.tableA");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_with_alias AS \n"
+ "SELECT * FROM (SELECT * from test.tableA) as viewFirst union all SELECT * FROM (SELECT * from test.tableA) as viewSecond");

run(driver, "CREATE TABLE IF NOT EXISTS test.tableB(a int, b struct<b1:string>)");
run(driver, "CREATE TABLE IF NOT EXISTS test.tableC(a int, b struct<b1:string>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_single_branch_evolved AS \n"
+ "SELECT * from test.tableB union all SELECT * from test.tableC");
run(driver, "ALTER TABLE test.tableC CHANGE COLUMN b b struct<b1:string, b2:int>");

run(driver, "CREATE TABLE IF NOT EXISTS test.tableD(a int, b struct<b1:string>)");
run(driver, "CREATE TABLE IF NOT EXISTS test.tableE(a int, b struct<b1:string>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_double_branch_evolved_same AS \n"
+ "SELECT * from test.tableD union all SELECT * from test.tableE");
run(driver, "ALTER TABLE test.tableD CHANGE COLUMN b b struct<b1:string, b2:int>");
run(driver, "ALTER TABLE test.tableE CHANGE COLUMN b b struct<b1:string, b2:int>");

run(driver, "CREATE TABLE IF NOT EXISTS test.tableF(a int, b struct<b1:string>)");
run(driver, "CREATE TABLE IF NOT EXISTS test.tableG(a int, b struct<b1:string>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_double_branch_evolved_different AS \n"
+ "SELECT * from test.tableF union all SELECT * from test.tableG");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_more_than_two_branches_evolved AS \n"
+ "SELECT * from test.tableF union all SELECT * from test.tableG union all SELECT * from test.tableF");
run(driver, "ALTER TABLE test.tableF CHANGE COLUMN b b struct<b1:string, b3:string>");
run(driver, "ALTER TABLE test.tableG CHANGE COLUMN b b struct<b1:string, b2:int>");

run(driver, "CREATE TABLE IF NOT EXISTS test.tableH(a int, b map<string, struct<b1:string>>)");
run(driver, "CREATE TABLE IF NOT EXISTS test.tableI(a int, b map<string, struct<b1:string>>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_map_with_struct_value_evolved AS \n"
+ "SELECT * from test.tableH union all SELECT * from test.tableI");
run(driver, "ALTER TABLE test.tableH CHANGE COLUMN b b map<string, struct<b1:string, b2:int>>");

run(driver, "CREATE TABLE IF NOT EXISTS test.tableJ(a int, b array<struct<b1:string>>)");
run(driver, "CREATE TABLE IF NOT EXISTS test.tableK(a int, b array<struct<b1:string>>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_array_with_struct_value_evolved AS \n"
+ "SELECT * from test.tableJ union all SELECT * from test.tableK");
run(driver, "ALTER TABLE test.tableJ CHANGE COLUMN b b array<struct<b1:string, b2:int>>");

run(driver,
"CREATE TABLE IF NOT EXISTS test.tableL(a int, b struct<b1:string, b2:struct<b3:string, b4:struct<b5:string>>>)");
run(driver,
"CREATE TABLE IF NOT EXISTS test.tableM(a int, b struct<b1:string, b2:struct<b3:string, b4:struct<b5:string>>>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_deeply_nested_struct_evolved AS \n"
+ "SELECT * from test.tableL union all SELECT * from test.tableM");
run(driver,
"ALTER TABLE test.tableL CHANGE COLUMN b b struct<b1:string, b2:struct<b3:string, b4:struct<b5:string, b6:string>>>");

run(driver,
"CREATE TABLE IF NOT EXISTS test.tableN(a int, b struct<b1:string, m1:map<string, struct<b1:string, a1:array<struct<b1:string>>>>>)");
run(driver,
String.join("\n", "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_deeply_nested_complex_struct_evolved AS ",
"SELECT * from test.tableN union all SELECT * from test.tableO"));
run(driver, String.join("\n",
"ALTER TABLE test.tableN CHANGE COLUMN b b struct<b1:string, m1:map<string, struct<b1:string, a1:array<struct<b0:string, b1:string>>>>>"));

run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.current_date_and_timestamp_view AS ",
"SELECT CURRENT_TIMESTAMP, trim(cast(CURRENT_TIMESTAMP as string)) as ct, CURRENT_DATE, CURRENT_DATE as cd, a from test.tableA"));
run(driver, String.join("\n", "CREATE VIEW IF NOT EXISTS test.get_json_object_view AS ",
"SELECT get_json_object(b.b1, '$.name') FROM test.tableA"));
"CREATE TABLE IF NOT EXISTS test.tableO(a int, b struct<b1:string, m1:map<string, struct<b1:string, a1:array<struct<b1:string>>>>>)");
run(driver, "CREATE VIEW IF NOT EXISTS test.fuzzy_union_view_deeply_nested_complex_struct_evolved AS \n"
+ "SELECT * from test.tableN union all SELECT * from test.tableO");
run(driver,
"ALTER TABLE test.tableN CHANGE COLUMN b b struct<b1:string, m1:map<string, struct<b1:string, a1:array<struct<b0:string, b1:string>>>>>");

run(driver, "CREATE VIEW IF NOT EXISTS test.current_date_and_timestamp_view AS \n"
+ "SELECT CURRENT_TIMESTAMP, trim(cast(CURRENT_TIMESTAMP as string)) as ct, CURRENT_DATE, CURRENT_DATE as cd, a from test.tableA");
run(driver, "CREATE VIEW IF NOT EXISTS test.get_json_object_view AS \n"
+ "SELECT get_json_object(b.b1, '$.name') FROM test.tableA");
}

public static RelNode convertView(String db, String view) {
Expand Down

0 comments on commit 89460e8

Please sign in to comment.