feat: Support Spark Expression Decode#4284
Conversation
|
Hi @comphead, thanks for the review, i've add decode to |
|
Hi @parthchandra |
| query expect_fallback(Comet only supports decoding with 'utf-8'.) | ||
| SELECT decode(b, 'ISO-8859-1') FROM test_decode_utf8 | ||
|
|
||
| -- Oracle-style form: decode(expr, search1, result1, ..., [default]) |
There was a problem hiding this comment.
Thanks @YutaLin. I'm not sure why we need oracle style? it might be confusing, other than that the PR looks good to go
There was a problem hiding this comment.
Hi @comphead, thanks for the review!
This is the legacy sql function originally created by Oracle. Before standard sql introduced case when statement, Oracle created Decode as a quick way to write If-Then-ELSE logic inside a query. Spark supports it purely for backward compatibility.
-- Oracle-style DECODE
SELECT DECODE(status_code, 1, 'Active', 2, 'Suspended', 'Unknown') FROM users;
-- Standard SQL Equivalent
SELECT
CASE status_code
WHEN 1 THEN 'Active'
WHEN 2 THEN 'Suspended'
ELSE 'Unknown'
END
FROM users;There was a problem hiding this comment.
Ic, lets just keep the test case without mentioning Oracle
|
I took the liberty to update the test, once CI is done we can merge the PR, thanks @YutaLin |
Which issue does this PR close?
Closes #3184
Rationale for this change
Decode is RuntimeReplaceable in Spark. It's computed through
Decode.createExprsoWe only need to add test to verify the behavior.
What changes are included in this PR?
Add
decode.sqlHow are these changes tested?
run encode.sql test in spark 3.4/3.5/4.0