You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SPARK-22520][SQL] Support code generation for large CaseWhen
## What changes were proposed in this pull request?
Code generation is disabled for CaseWhen when the number of branches is higher than `spark.sql.codegen.maxCaseBranches` (which defaults to 20). This was done to prevent the well known 64KB method limit exception.
This PR proposes to support code generation also in those cases (without causing exceptions of course). As a side effect, we could get rid of the `spark.sql.codegen.maxCaseBranches` configuration.
## How was this patch tested?
existing UTs
Author: Marco Gaido <[email protected]>
Author: Marco Gaido <[email protected]>
Closes#19752 from mgaido91/SPARK-22520.
@@ -88,14 +88,34 @@ case class If(predicate: Expression, trueValue: Expression, falseValue: Expressi
88
88
}
89
89
90
90
/**
91
-
* Abstract parent class for common logic in CaseWhen and CaseWhenCodegen.
91
+
* Case statements of the form "CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END".
92
+
* When a = true, returns b; when c = true, returns d; else returns e.
92
93
*
93
94
* @parambranches seq of (branch condition, branch value)
94
95
* @paramelseValue optional value for the else branch
95
96
*/
96
-
abstractclassCaseWhenBase(
97
+
// scalastyle:off line.size.limit
98
+
@ExpressionDescription(
99
+
usage ="CASE WHEN expr1 THEN expr2 [WHEN expr3 THEN expr4]* [ELSE expr5] END - When `expr1` = true, returns `expr2`; else when `expr3` = true, returns `expr4`; else returns `expr5`.",
100
+
arguments ="""
101
+
Arguments:
102
+
* expr1, expr3 - the branch condition expressions should all be boolean type.
103
+
* expr2, expr4, expr5 - the branch value expressions and else value expression should all be
104
+
same type or coercible to a common type.
105
+
""",
106
+
examples ="""
107
+
Examples:
108
+
> SELECT CASE WHEN 1 > 0 THEN 1 WHEN 2 > 0 THEN 2.0 ELSE 1.2 END;
109
+
1
110
+
> SELECT CASE WHEN 1 < 0 THEN 1 WHEN 2 > 0 THEN 2.0 ELSE 1.2 END;
111
+
2
112
+
> SELECT CASE WHEN 1 < 0 THEN 1 WHEN 2 < 0 THEN 2.0 END;
* Case statements of the form "CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END".
166
-
* When a = true, returns b; when c = true, returns d; else returns e.
167
-
*
168
-
* @parambranches seq of (branch condition, branch value)
169
-
* @paramelseValue optional value for the else branch
170
-
*/
171
-
// scalastyle:off line.size.limit
172
-
@ExpressionDescription(
173
-
usage ="CASE WHEN expr1 THEN expr2 [WHEN expr3 THEN expr4]* [ELSE expr5] END - When `expr1` = true, returns `expr2`; else when `expr3` = true, returns `expr4`; else returns `expr5`.",
174
-
arguments ="""
175
-
Arguments:
176
-
* expr1, expr3 - the branch condition expressions should all be boolean type.
177
-
* expr2, expr4, expr5 - the branch value expressions and else value expression should all be
178
-
same type or coercible to a common type.
179
-
""",
180
-
examples ="""
181
-
Examples:
182
-
> SELECT CASE WHEN 1 > 0 THEN 1 WHEN 2 > 0 THEN 2.0 ELSE 1.2 END;
183
-
1
184
-
> SELECT CASE WHEN 1 < 0 THEN 1 WHEN 2 > 0 THEN 2.0 ELSE 1.2 END;
185
-
2
186
-
> SELECT CASE WHEN 1 < 0 THEN 1 WHEN 2 < 0 THEN 2.0 ELSE null END;
0 commit comments