Skip to content

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

Merged
findepi merged 1 commit intotrinodb:masterfrom
findinpath:findinpath/union-char-varchar
Oct 27, 2023
Merged

Cast char fields, if necessary, to varchar type in Hive view translations#19275
findepi merged 1 commit intotrinodb:masterfrom
findinpath:findinpath/union-char-varchar

Conversation

@findinpath
Copy link
Copy Markdown
Contributor

@findinpath findinpath commented Oct 5, 2023

Description

Bump coral to 2.2.14 to support Hive view translation cnsisting of a UNION between a char and a varchar field.

Due to wrong coercion between varchar and char in Trino, as described in #9031
, a work-around needs to be applied in case of translating Hive views which contain a UNION dealing with char and varchar types. The work-around consists in the explicit cast of the field having char type towards varchar type corresponding of the set operation output type.

Fixes #18337

Additional context and related issues

linkedin/coral#442

trinodb/trino-coral#2

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

# Hive
* Cast char fields, if necessary, to varchar type in Hive view translations. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Oct 5, 2023
@findinpath findinpath changed the title Cast char fields, if necessary, to varchar type in view translations Cast char fields, if necessary, to varchar type in Hive view translations Oct 5, 2023
@github-actions github-actions bot added tests:hive hive Hive connector labels Oct 5, 2023
@findinpath findinpath force-pushed the findinpath/union-char-varchar branch from 9300f57 to 5435e80 Compare October 23, 2023 19:14
Bump coral to 2.2.14 to support Hive view translation cnsisting of a UNION
between a char and a varchar field.

Due to wrong coercion between `varchar` and `char` in Trino, as described in
trinodb#9031
, a work-around needs to be applied in case of translating Hive views which
contain a UNION dealing with char and varchar types.
The work-around consists in the explicit cast of the field
having char type towards varchar type corresponding of the set operation
output type.
@findinpath findinpath force-pushed the findinpath/union-char-varchar branch from 5435e80 to 33f1bc6 Compare October 26, 2023 03:37
@findinpath findinpath marked this pull request as ready for review October 26, 2023 03:38
@findinpath findinpath self-assigned this Oct 26, 2023

@Test(groups = HIVE_VIEWS)
@Flaky(issue = RETRYABLE_FAILURES_ISSUES, match = RETRYABLE_FAILURES_MATCH)
public void testUnionBetweenCharAndVarchar()
Copy link
Copy Markdown
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
Copy Markdown
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)

@findinpath findinpath requested a review from findepi October 26, 2023 15:30
@findepi findepi merged commit 9894dbb into trinodb:master Oct 27, 2023
@github-actions github-actions bot added this to the 431 milestone Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed hive Hive connector

Development

Successfully merging this pull request may close these issues.

Hive view translation containing a UNION between a varchar(65535) and a char(1) fails because of coercion to char(65535)

3 participants