Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast char fields, if necessary, to varchar type in Hive view translations #19275

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewColumn> columns = rowType.getFieldList().stream()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@
<dependency>
<groupId>io.trino.coral</groupId>
<artifactId>coral</artifactId>
<version>2.0.153-1</version>
<version>2.2.14-1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this go to AbstractTestHiveViews?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not.

testing/bin/ptl test run --environment multinode --config config-default --  -t io.trino.tests.product.hive.TestHiveViewsLegacy.testUnionBetweenCharAndVarchar
Caused by: io.trino.spi.TrinoException: line 1:15: View 'hive.default.union_char_varchar_view' is stale or in invalid state: column [col] of type char(1024) projected from query view at position 0 cannot be coerced to column [col] of type varchar stored in view definition
tests               | 	at io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:48)
tests               | 	at io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:43)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.lambda$createScopeForView$56(StatementAnalyzer.java:2493)
tests               | 	at java.base/java.util.Optional.ifPresent(Optional.java:178)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.createScopeForView(StatementAnalyzer.java:2493)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.createScopeForView(StatementAnalyzer.java:2446)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.visitTable(StatementAnalyzer.java:2238)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.visitTable(StatementAnalyzer.java:493)
tests               | 	at io.trino.sql.tree.Table.accept(Table.java:60)
tests               | 	at io.trino.sql.tree.AstVisitor.process(AstVisitor.java:27)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:512)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.analyzeFrom(StatementAnalyzer.java:4560)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.visitQuerySpecification(StatementAnalyzer.java:3020)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.visitQuerySpecification(StatementAnalyzer.java:493)
tests               | 	at io.trino.sql.tree.QuerySpecification.accept(QuerySpecification.java:155)
tests               | 	at io.trino.sql.tree.AstVisitor.process(AstVisitor.java:27)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:512)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:520)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.visitQuery(StatementAnalyzer.java:1521)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.visitQuery(StatementAnalyzer.java:493)
tests               | 	at io.trino.sql.tree.Query.accept(Query.java:107)
tests               | 	at io.trino.sql.tree.AstVisitor.process(AstVisitor.java:27)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:512)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer.analyze(StatementAnalyzer.java:472)
tests               | 	at io.trino.sql.analyzer.StatementAnalyzer.analyze(StatementAnalyzer.java:461)
tests               | 	at io.trino.sql.analyzer.Analyzer.analyze(Analyzer.java:97)
tests               | 	at io.trino.sql.analyzer.Analyzer.analyze(Analyzer.java:86)
tests               | 	at io.trino.execution.SqlQueryExecution.analyze(SqlQueryExecution.java:274)
tests               | 	at io.trino.execution.SqlQueryExecution.<init>(SqlQueryExecution.java:209)
tests               | 	at io.trino.execution.SqlQueryExecution$SqlQueryExecutionFactory.createQueryExecution(SqlQueryExecution.java:850)
tests               | 	at io.trino.dispatcher.LocalDispatchQueryFactory.lambda$createDispatchQuery$0(LocalDispatchQueryFactory.java:153)
tests               | 	at io.trino.$gen.Trino_426_726_g33f1bc6_dirty____20231026_151108_2.call(Unknown Source)

{
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<QueryAssert.Row> 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");
}
}
Loading