Description
Currently, there is no native support for SQL-style CASE expressions in eval. This limitation makes it difficult to implement multi-branch conditional logic in a clear and maintainable way. Users are required to nest multiple IF() functions, which reduces readability and increases the complexity of query construction and maintenance.
Goal
Add support for standard CASE WHEN ... THEN ... ELSE ... END syntax in PPL, particularly within eval, to allow users to define conditional logic more intuitively and clearly. This functionality would align PPL with widely adopted SQL syntax and improve query clarity in scenarios requiring multi-condition branching.
Workarounds and alternatives
Nested IF() expressions have been used to replicate CASE logic. However, this approach becomes cumbersome and error-prone as the number of conditions increases, and lacks the structural clarity provided by CASE statements.
Reference
- Example by using
IF (as the work around for now):
| eval grade = if(score >= 95, "A+",
if(score >= 90, "A",
if(score >= 85, "B+",
if(score >= 80, "B",
if(score >= 75, "C+",
if(score >= 70, "C",
if(score >= 65, "D+",
if(score >= 60, "D", "F"))))))))
# As more conditions are added, readability degrades significantly
| eval grade = case(
when score >= 95 then "A+",
when score >= 90 then "A",
when score >= 85 then "B+",
when score >= 80 then "B",
when score >= 75 then "C+",
when score >= 70 then "C",
when score >= 65 then "D+",
when score >= 60 then "D",
else "F"
)
Description
Currently, there is no native support for SQL-style
CASEexpressions ineval. This limitation makes it difficult to implement multi-branch conditional logic in a clear and maintainable way. Users are required to nest multipleIF()functions, which reduces readability and increases the complexity of query construction and maintenance.Goal
Add support for standard
CASE WHEN ... THEN ... ELSE ... ENDsyntax in PPL, particularly withineval, to allow users to define conditional logic more intuitively and clearly. This functionality would align PPL with widely adopted SQL syntax and improve query clarity in scenarios requiring multi-condition branching.Workarounds and alternatives
Nested
IF()expressions have been used to replicateCASElogic. However, this approach becomes cumbersome and error-prone as the number of conditions increases, and lacks the structural clarity provided byCASEstatements.Reference
IF(as the work around for now):CASE: