diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/ViewReaderUtil.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/ViewReaderUtil.java index dfcfb2ebae68d..4e9cffb9f7233 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/ViewReaderUtil.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/ViewReaderUtil.java @@ -242,7 +242,7 @@ public ConnectorViewDefinition decodeViewData(String viewSql, Table table, Catal try { HiveToRelConverter hiveToRelConverter = new HiveToRelConverter(metastoreClient); RelNode rel = hiveToRelConverter.convertView(table.getDatabaseName(), table.getTableName()); - RelToTrinoConverter relToTrino = new RelToTrinoConverter(); + RelToTrinoConverter relToTrino = new RelToTrinoConverter(metastoreClient); String trinoSql = relToTrino.convert(rel); RelDataType rowType = rel.getRowType(); List columns = rowType.getFieldList().stream() diff --git a/pom.xml b/pom.xml index 55e50d7382b1e..11b6d26c26efc 100644 --- a/pom.xml +++ b/pom.xml @@ -1436,7 +1436,7 @@ io.trino.coral coral - 2.0.153-1 + 2.2.14-1 diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveViews.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveViews.java index a29d50aea8379..9a6815e8b5d1f 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveViews.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveViews.java @@ -541,4 +541,32 @@ public void testCastTimestampAsDecimal() onHive().executeQuery("DROP VIEW cast_timestamp_as_decimal_view"); onHive().executeQuery("DROP TABLE cast_timestamp_as_decimal"); } + + @Test(groups = HIVE_VIEWS) + @Flaky(issue = RETRYABLE_FAILURES_ISSUES, match = RETRYABLE_FAILURES_MATCH) + public void testUnionBetweenCharAndVarchar() + { + onHive().executeQuery("DROP TABLE IF EXISTS union_char_varchar"); + onHive().executeQuery("CREATE TABLE union_char_varchar (a_char char(1), a_varchar varchar(1024))"); + onHive().executeQuery("INSERT INTO union_char_varchar VALUES ('a', 'Trino')"); + onHive().executeQuery("INSERT INTO union_char_varchar VALUES (NULL, NULL)"); + onHive().executeQuery("DROP VIEW IF EXISTS union_char_varchar_view"); + onHive().executeQuery(""" + CREATE VIEW union_char_varchar_view AS + SELECT a_char AS col FROM union_char_varchar + UNION ALL + SELECT a_varchar AS col FROM union_char_varchar + """); + + List expected = List.of( + row("a"), + row("Trino"), + row((Object) null), + row((Object) null)); + assertThat(onTrino().executeQuery("SELECT * FROM union_char_varchar_view")).containsOnly(expected); + assertThat(onHive().executeQuery("SELECT * FROM union_char_varchar_view")).containsOnly(expected); + + onHive().executeQuery("DROP VIEW union_char_varchar_view"); + onHive().executeQuery("DROP TABLE union_char_varchar"); + } }