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

[Coral-Trino] Fix substring start index issue #499

Merged
merged 9 commits into from
Apr 11, 2024

Conversation

KevinGe00
Copy link
Contributor

@KevinGe00 KevinGe00 commented Mar 15, 2024

What changes are proposed in this pull request, and why are they necessary?

#434 suggested that Hive substring function start index is 0-based, while Trino is 1-based. Upon further investigation, we found that both Hive and Trino indexes are actually 1-based (this was the behavior before #434). The only difference is that Hive also allows 0 as a starting substring index and treats it as 1 (this was not the behavior before #434, where 0 in Hive simply mapped to 0 in Trino). #434 was reverted in #492 but the revert was released in a hot fix branch. This PR corrects the behavior to the expected semantics.

hive (u_kge)> select substr('123', 0, 3) as a;
OK
123

hive (u_kge)> select substr('123', 1, 3) as a;
OK
123

trino> select substr('123', 0, 3) as a;
 a 
---
   
(1 row)

trino> select substr('123', 1, 3) as a;
  a  
-----
 123 
(1 row)

To fix this, when translating from Hive to Trino, we ensure that if the hive starting substring index is 0, we change it to 1, while leaving any other index number the same. Use CASE WHEN if start index is another column (we don't know the actual value).

How was this patch tested?

./gradlew build
updated + New unit tests
regression tests pending, Update: all regressions expected

@ljfgem ljfgem changed the title Coral-Trino] Fix substring start index issue [Coral-Trino] Fix substring start index issue Mar 15, 2024
Copy link
Collaborator

@ljfgem ljfgem left a comment

Choose a reason for hiding this comment

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

Thank you @KevinGe00 for this PR!

Copy link
Contributor

@wmoustafa wmoustafa left a comment

Choose a reason for hiding this comment

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

LGTM after minor style fix and integration tests

@@ -135,7 +125,7 @@ protected SqlCall transform(SqlCall sqlCall) {
new GenericCoralRegistryOperatorRenameSqlCallTransformer(),

new ReturnTypeAdjustmentTransformer(configs), new UnnestOperatorTransformer(), new AsOperatorTransformer(),
new JoinSqlCallTransformer(), new NullOrderingTransformer());
new JoinSqlCallTransformer(), new NullOrderingTransformer(), new SubstrIndexTransformer());
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make sure every transformer is added in a new line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spotlessApply forces this formatting

Copy link
Collaborator

@ljfgem ljfgem left a comment

Choose a reason for hiding this comment

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

Overall LGTM, thank you for the fix @KevinGe00 !

Copy link
Collaborator

@ljfgem ljfgem left a comment

Choose a reason for hiding this comment

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

LGTM

@KevinGe00 KevinGe00 merged commit 0d5dd3f into linkedin:master Apr 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants