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

[SPARK-41668][SQL] DECODE function returns wrong results when passed NULL #39163

Closed
wants to merge 1 commit into from

Conversation

gengliangwang
Copy link
Member

What changes were proposed in this pull request?

The DECODE function was implemented for Oracle compatibility. It works similar to CASE expression, but it is supposed to have one major difference: NULL == NULL
https://docs.oracle.com/database/121/SQLRF/functions057.htm#SQLRF00631

The Spark implementation does not observe this, however:

> select decode(null, 6, 'Spark', NULL, 'SQL', 4, 'rocks');

NULL

The result is supposed to be 'SQL'. This PR is to fix the issue.

Why are the changes needed?

Bug fix and Oracle compatibility.

Does this PR introduce any user-facing change?

Yes, DECODE function will return matched value when passed null, instead of always returning null.

How was this patch tested?

New UT.

@gengliangwang
Copy link
Member Author

cc @srielau @beliefer

Copy link
Contributor

@beliefer beliefer left a comment

Choose a reason for hiding this comment

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

@gengliangwang Thank you for the catch!

@gengliangwang
Copy link
Member Author

gengliangwang commented Dec 22, 2022

Merging to master/3.3

gengliangwang added a commit that referenced this pull request Dec 22, 2022
…NULL

### What changes were proposed in this pull request?

The DECODE function was implemented for Oracle compatibility. It works similar to CASE expression, but it is supposed to have one major difference: NULL == NULL
https://docs.oracle.com/database/121/SQLRF/functions057.htm#SQLRF00631

The Spark implementation does not observe this, however:
```
> select decode(null, 6, 'Spark', NULL, 'SQL', 4, 'rocks');

NULL
```

The result is supposed to be 'SQL'. This PR is to fix the issue.

### Why are the changes needed?

Bug fix and Oracle compatibility.

### Does this PR introduce _any_ user-facing change?

Yes, DECODE function will return matched value when passed null, instead of always returning null.
### How was this patch tested?

New UT.

Closes #39163 from gengliangwang/fixDecode.

Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
(cherry picked from commit e09fceb)
Signed-off-by: Gengliang Wang <gengliang@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants