-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Handle nulls in approx_percentile_cont #11721
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
Handle nulls in approx_percentile_cont #11721
Conversation
|
|
||
| if args.ignore_nulls { | ||
| return not_impl_err!( | ||
| "IGNORE NULLS clause not yet supported for APPROX_PERCENTILE_CONT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectively this fix actually does ignore nulls, but we don't have a way to disable setting RESPECT NULLS for aggregate functions, I can file a follow-up ticket.
I believe we should also move DataFusion to SELECT percentile_cont(0.5) WITHIN GROUP(order by v) (used by PostgreSQL, others) syntax...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can trigger it if used as a window function PERCENTILE_CONT(...) OVER (PARTITION BY ... IGNORE NULLS) 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... for now I think it makes sense to ignore the ignore_nulls argument (like we did before) and remove any nulls which makes the most sense. Null handling is broken anyway (resulting in 0 instead of NULL), so no one will rely on percentile_cont on columns with nulls.
I'll file a ticket to discuss standardizing PERCENTILE_CONT and having it behave like PostgreSQL / Spark / Snowflake, etc....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Dandandan
| query I | ||
| SELECT APPROX_PERCENTILE_CONT(v, 0.5) FROM (VALUES (1), (2), (3), (NULL), (NULL), (NULL)) as t (v); | ||
| ---- | ||
| 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was 0 before (not even NULL)
Which issue does this PR close?
Closes #11720
Rationale for this change
Fix a bug in
approx_percentile_contwhen having nulls in inputWhat changes are included in this PR?
Filters input arrays on nulls if present
Are these changes tested?
Yes, additional sql test
Are there any user-facing changes?
Just the fix