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 nulls ordering for Range frames #9271

Closed
wants to merge 1 commit into from
Closed

Conversation

aditi-pandit
Copy link
Collaborator

@aditi-pandit aditi-pandit commented Mar 27, 2024

The nullsFirst flag weren't correctly passed in column comparisons for range frames. This caused range values for nulls to match those of adjacent rows for desc nulls last and asc nulls first order clauses.

Setting the CompareFlags also made me realize an improvement to simplify the code.

Fixes prestodb/presto#21889

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 27, 2024
Copy link

netlify bot commented Mar 27, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit defb7cc
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/661edb339262eb0008a3e345

Comment on lines 276 to 285
if constexpr (isAscending) {
flags.nullsFirst = sortKeyInfo_[0].second.isNullsFirst();
} else {
flags.nullsFirst = !sortKeyInfo_[0].second.isNullsFirst();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why we don't simply set flags = {sortKeyInfo_[0].second.isNullsFirst(), isAscending, false} but need this custom logic instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kagamiori : The actual data could be ascending or descending ordered (depending on ORDER BY). The range frame is trying to find a particular value in the ORDER BY column. But depending on preceding/following asc/desc we look for smallest value greater than or greatest value less than. The comparisons for this were simpler to write if the comparison test was with asc semantics only. So the comparison flags are always ascending (like you have put together), but the nulls flag needs to flip depending on asc/desc and how it compares with values in ascending semantics.

Hope this sounds okay. We can discuss if you need further clarification on slack/workspace.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. This makes sense to me. Thank you for explaining! Could we add a comment here with this explanation too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kagamiori : As I played with the comparisons more, this code could be simplified keeping CompareFlags consistent with the ordering. I think the current code reads well with the current comments. But please let me know your suggestions.

@aditi-pandit
Copy link
Collaborator Author

The connbench regressions are unrelated to the code in this PR.

Copy link
Contributor

@kagamiori kagamiori left a comment

Choose a reason for hiding this comment

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

LGTM. Shall we add the test coverage in WindowTestBase as well?
(cc'ing @mbasmanova in case she has any concern with this usage of CompareFlags.)

Comment on lines 276 to 285
if constexpr (isAscending) {
flags.nullsFirst = sortKeyInfo_[0].second.isNullsFirst();
} else {
flags.nullsFirst = !sortKeyInfo_[0].second.isNullsFirst();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. This makes sense to me. Thank you for explaining! Could we add a comment here with this explanation too?

@aditi-pandit
Copy link
Collaborator Author

@kagamiori, @mbasmanova : On second thoughts, there is some more simplification possible.

I'm moving this PR to draft mode and will open for review again.

@aditi-pandit aditi-pandit marked this pull request as draft April 3, 2024 06:23
@aditi-pandit aditi-pandit force-pushed the window_range_null branch 2 times, most recently from 4538cef to 52094b8 Compare April 4, 2024 23:58
@aditi-pandit aditi-pandit marked this pull request as ready for review April 4, 2024 23:59
@aditi-pandit
Copy link
Collaborator Author

aditi-pandit commented Apr 5, 2024

LGTM. Shall we add the test coverage in WindowTestBase as well? (cc'ing @mbasmanova in case she has any concern with this usage of CompareFlags.)

@kagamiori : This PR is ready for review now. I added array_agg function in the rest of the range frame testing as well.

Copy link
Contributor

@kagamiori kagamiori left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the fix.

@facebook-github-bot
Copy link
Contributor

@kagamiori has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@kagamiori has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@kagamiori merged this pull request in da6a3d3.

Copy link

Conbench analyzed the 1 benchmark run on commit da6a3d30.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

@aditi-pandit aditi-pandit deleted the window_range_null branch April 25, 2024 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Native] - Testcase testZeroOffset() fails against c++ worker.
4 participants