Skip to content

feat: Support Spark Expression Decode#4284

Open
YutaLin wants to merge 6 commits into
apache:mainfrom
YutaLin:3184_support_expression_decode
Open

feat: Support Spark Expression Decode#4284
YutaLin wants to merge 6 commits into
apache:mainfrom
YutaLin:3184_support_expression_decode

Conversation

@YutaLin
Copy link
Copy Markdown

@YutaLin YutaLin commented May 10, 2026

Which issue does this PR close?

Closes #3184

Rationale for this change

Decode is RuntimeReplaceable in Spark. It's computed through Decode.createExpr so

  • 2-arg decode is transformed into StringDecode, which Comet already handles through stringDecode(utf-8 only)
  • n-arg decode is transformed into CaseWhen, which Comet also supports.

We only need to add test to verify the behavior.

What changes are included in this PR?

Add decode.sql

How are these changes tested?

run encode.sql test in spark 3.4/3.5/4.0

Copy link
Copy Markdown
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

Thanks @YutaLin please add also decode to docs/source/contributor-guide/spark_expressions_support.md

@YutaLin
Copy link
Copy Markdown
Author

YutaLin commented May 11, 2026

Hi @comphead, thanks for the review, i've add decode to spark_expressions_support

@YutaLin YutaLin requested a review from comphead May 11, 2026 21:04
@YutaLin
Copy link
Copy Markdown
Author

YutaLin commented May 13, 2026

Hi @parthchandra
Can you help me trigger CI? Thanks!

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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @YutaLin. I'm not sure why we need oracle style? it might be confusing, other than that the PR looks good to go

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ic, lets just keep the test case without mentioning Oracle

@YutaLin YutaLin requested a review from comphead May 14, 2026 17:00
Comment thread spark/src/test/resources/sql-tests/expressions/string/decode.sql Outdated
@comphead
Copy link
Copy Markdown
Contributor

I took the liberty to update the test, once CI is done we can merge the PR, thanks @YutaLin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support Spark expression: decode

2 participants