From ab617d13fe415f8bc2c37e7d5f31200c3484cdf9 Mon Sep 17 00:00:00 2001 From: Marius Grama Date: Tue, 1 Mar 2022 07:28:34 +0100 Subject: [PATCH] Test translation of view with namesake column aliases which are differing 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. --- .../product/hive/AbstractTestHiveViews.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/AbstractTestHiveViews.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/AbstractTestHiveViews.java index 7c77d79c6c9f..aeb6846e3dfe 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/AbstractTestHiveViews.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/AbstractTestHiveViews.java @@ -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 assertion) { // Ensure Hive and Presto view compatibility by comparing the results