apache / apache/spark

[SQL] Add CASE WHEN equivalent for the DECODE function

Open
#57,534 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
44k
Forks
29.4k
PR merge metrics
No merged PRs in 30d

Description

Currently, the `decode` function is used only for decoding strings. However, a `CASE WHEN` equivalent has been available in the Spark SQL API since version 3.2.0

https://spark.apache.org/docs/latest/api/sql/string-functions/#decode

```
> SELECT decode(encode('abc', 'utf-8'), 'utf-8');
abc
> SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic');
Non domestic
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked Spark SQL DECODE documentation and the existing DECODE SQL entry point, comparing the string-decoding examples with the requested CASE WHEN form. Trace where SQL function behavior is covered by tests, then verify that the new conditional form works without regressing the existing examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala, sql
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.