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

fix(ir): merge window frames for bound analytic window functions with a subsequent over call #7790

Merged
merged 2 commits into from
Dec 18, 2023

Conversation

kszucs
Copy link
Member

@kszucs kszucs commented Dec 17, 2023

Fixes #7631

#7327 removed the argument of the relevant analytic functions and changed the value methods to return with a WindowFunction with a frame ordered by the value. When .over() is called on a window function the window frames were not merged, while we had that functionality it was only used by the table.group_by().select(reduction | analytic) API calls (the GroupedTable helper object).

This PR changes the .over() method to merge the window builder provided in the call with the window already existing in the expression if any. It also deduplicates the order_by and group_by expressions during merge now.

@kszucs kszucs force-pushed the percent-rank-bug branch 2 times, most recently from 2b283fd to 2c02b3b Compare December 17, 2023 23:15
@@ -48,10 +50,24 @@ def test_value_over_api(alltypes):
w1 = ibis.window(rows=(0, 1), group_by=t.g, order_by=[t.f, t.h])
w2 = ibis.window(range=(-1, 1), group_by=[t.g, t.a], order_by=[t.f])

expr = t.f.cumsum().over(rows=(0, 1), group_by=t.g, order_by=[t.f, t.h])
Copy link
Member Author

Choose a reason for hiding this comment

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

I think we have been misinterpreting this scenario because we used the cumulative_window() frame constructed in the cumsum() call, but we also provided explicit rows window boundaries. I changed the behaviour to raise due to window frame boundary conflict.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that makes sense to me.

@kszucs kszucs force-pushed the percent-rank-bug branch 5 times, most recently from 38e3239 to 3d129f9 Compare December 18, 2023 12:55
Copy link
Member

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

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

Small change request, but otherwise LGTM!

@@ -48,10 +50,24 @@ def test_value_over_api(alltypes):
w1 = ibis.window(rows=(0, 1), group_by=t.g, order_by=[t.f, t.h])
w2 = ibis.window(range=(-1, 1), group_by=[t.g, t.a], order_by=[t.f])

expr = t.f.cumsum().over(rows=(0, 1), group_by=t.g, order_by=[t.f, t.h])
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that makes sense to me.

ibis/tests/expr/test_window_functions.py Outdated Show resolved Hide resolved
@cpcloud cpcloud added this to the 7.2 milestone Dec 18, 2023
@cpcloud cpcloud added bug Incorrect behavior inside of ibis regression Issues related to things that used to work but don't anymore labels Dec 18, 2023
@cpcloud cpcloud merged commit 66fd69c into ibis-project:master Dec 18, 2023
81 checks passed
@cpcloud
Copy link
Member

cpcloud commented Dec 18, 2023

Might need to regen some code in the cloud backends, lemme see.

@kszucs kszucs deleted the percent-rank-bug branch December 18, 2023 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis regression Issues related to things that used to work but don't anymore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: regression with percent_rank compilation in 7.x (Deferred related?)
2 participants