Skip to content

Unwrap IN predicate for 'cast in' and for 'date trunc'#18138

Closed
kabunchi wants to merge 4 commits intotrinodb:masterfrom
kabunchi:unwrap-in2
Closed

Unwrap IN predicate for 'cast in' and for 'date trunc'#18138
kabunchi wants to merge 4 commits intotrinodb:masterfrom
kabunchi:unwrap-in2

Conversation

@kabunchi
Copy link
Copy Markdown

@kabunchi kabunchi commented Jul 5, 2023

Description

Additional context and related issues

Release notes

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

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Jul 5, 2023
@findepi findepi requested review from ebyhr and martint July 5, 2023 12:29
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.

Instead of creating a comparison expression, change unwrapCast to take the three components of a comparison expression (operation, left, right) and call it directly: unwrapCast(EQUAL, value, rightExpression)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

implemented it in a different commit, had to change the return type of unwrapCast to Optional<Expression> because in this code I need to know if the unwrap happened or not, so it turned out to be more touched lines than I thought...
take a look.
had to rebase to get the already merged changes to UnwrapYear... aligned with the proposed change

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.

What's reverseOrder and why do we need it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

as you can see below, when using IN predicate the output is in reverse order relatively to the input and the assertPlan does not handle it cleanly.
instead of IN() OR rand we get rand OR IN() which is equivalent logically of course.
As I assumed it's not a faulty behavior of the engine I thought this was the simplest solution, happy to consider other options.

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.

The usage of that specific query and predicate is an internal implementation detail of the testUnwrap function. If that's not working in general, we need to come up with a different way to test that an expression is being unwrapped properly.

Regarding the expression being reordered by the engine, we should look into why that is happening. In general, we try to preserve the order unless we can determine that one expression is cheaper to evaluate first (they currently get evaluated left to right)

@findepi
Copy link
Copy Markdown
Member

findepi commented Jul 6, 2023

Unwrap in2

Can you please give this PR a title?


// Simplify `year(d) ? value`
private Expression unwrapYear(ComparisonExpression expression)
private Optional<Expression> unwrapYear(ComparisonExpression.Operator operator, Expression leftExpression, Expression rightExpression)
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.

this is in Review comments - to be squashed before merge commit, but there is nowhere to squash this into.

it looks like @martint has comments that would best apply in #18138, so maybe let's extract UnwrapYearInComparison to separate PR (or at least a prep commit)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it will be in a different commit of course.
not sure a separate PR is needed.

@kabunchi kabunchi changed the title Unwrap in2 Unwrap IN predicate for 'cast in' and for 'date trunc' Jul 6, 2023
@github-actions
Copy link
Copy Markdown

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Jan 12, 2024
@mosabua
Copy link
Copy Markdown
Member

mosabua commented Jan 12, 2024

👋 @kabunchi @martint - this PR has become inactive. We hope you are still interested in working on it. Please let us know, and we can try to get reviewers to help with that.

We're working on closing out old and inactive PRs, so if you're too busy or this has too many merge conflicts to be worth picking back up, we'll be making another pass to close it out in a few weeks.

@github-actions github-actions bot removed the stale label Jan 15, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 5, 2024

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Feb 5, 2024
@kabunchi kabunchi closed this Feb 5, 2024
@kabunchi kabunchi deleted the unwrap-in2 branch February 5, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants