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

handle 0 and NULL value of NTH_VALUE function #12676

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thinh2
Copy link
Contributor

@thinh2 thinh2 commented Sep 30, 2024

Which issue does this PR close?

Closes #12320.

Rationale for this change

The root cause in #12320 is because get_signed_integer_value will return an error on NULL or Int64(NULL) value. To process the nth_value function, it requires the n value should be an integer. Therefore, I decided to convert NULL value to 0 in get_signed_integer_value and implement handler for the 0 case. This will evaluate to NULL value for the nth_value(v1, NULL) expression.

Furthermore, it also evaluate the nth_value(v1, 0) to NULL instead of generating panic, which match the expected behaviour in duckdb.

What changes are included in this PR?

[x] Return 0 for NULL value in get_signed_integer
[x] Handle nth_value execution when n is 0
[x] Test file updated to test nth_value(v2, 0), nth_value(v2, NULL) and nth_value(v2, v2 * NULL).

Are these changes tested?

Yes

Are there any user-facing changes?

@github-actions github-actions bot added physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt) labels Sep 30, 2024
Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in nth_value() window function for NULL input (SQLancer)
3 participants