Skip to content

Commit

Permalink
Test translation of view with namesake column aliases which are diffe…
Browse files Browse the repository at this point in the history
…ring in case

In the translation of Hive views with Coral,
when joining tables that have the namesake column names,
irrespective of their case, make sure that the resulting
relation is using names of the columns which are
unique in order to avoid the situation where the
SQL statement created contains ambiguous column names.
  • Loading branch information
findinpath committed Mar 8, 2022
1 parent b75805a commit ab617d1
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,32 @@ public void testViewReferencingHiveAndIcebergTables()
onHive().executeQuery("DROP TABLE default.view_iceberg_table");
}

@Test(groups = HIVE_VIEWS)
public void testViewWithColumnAliasesDifferingInCase()
{
onHive().executeQuery("DROP TABLE IF EXISTS test_hive_namesake_column_name_a");
onHive().executeQuery("DROP TABLE IF EXISTS test_hive_namesake_column_name_b");
onHive().executeQuery("CREATE TABLE test_hive_namesake_column_name_a(some_id string)");
onHive().executeQuery("CREATE TABLE test_hive_namesake_column_name_b(SOME_ID string)");
onHive().executeQuery("INSERT INTO TABLE test_hive_namesake_column_name_a VALUES ('hive')");
onHive().executeQuery("INSERT INTO TABLE test_hive_namesake_column_name_b VALUES (' hive ')");

onHive().executeQuery("DROP VIEW IF EXISTS test_namesake_column_names_view");
onHive().executeQuery("" +
"CREATE VIEW test_namesake_column_names_view AS \n" +
" SELECT a.some_id FROM test_hive_namesake_column_name_a a \n" +
" LEFT JOIN (SELECT trim(SOME_ID) AS SOME_ID FROM test_hive_namesake_column_name_b) b \n" +
" ON a.some_id = b.some_id \n" +
" WHERE a.some_id != ''");
assertViewQuery(
"SELECT * FROM test_namesake_column_names_view",
queryAssert -> queryAssert.containsOnly(row("hive")));

onHive().executeQuery("DROP TABLE test_hive_namesake_column_name_a");
onHive().executeQuery("DROP TABLE test_hive_namesake_column_name_b");
onHive().executeQuery("DROP VIEW test_namesake_column_names_view");
}

protected static void assertViewQuery(String query, Consumer<QueryAssert> assertion)
{
// Ensure Hive and Presto view compatibility by comparing the results
Expand Down

0 comments on commit ab617d1

Please sign in to comment.