-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33798][SQL] Add new rule to push down the foldable expressions through CaseWhen/If #30790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
19b0a83
831bf66
859893d
db584ef
55f4528
0a48048
f9f622f
21ef0c3
d5135ec
8ccc3c1
45b56fc
cfac0e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,16 +203,17 @@ class SimplifyConditionalSuite extends PlanTest with ExpressionEvalHelper with P | |
| test("SPARK-33798: simplify EqualTo(If, Literal) always false") { | ||
| val a = EqualTo(UnresolvedAttribute("a"), Literal(100)) | ||
| val b = UnresolvedAttribute("b") | ||
| val ifExp = If(a === Literal(1), Literal(2), Literal(3)) | ||
| val ifExp = If(a, Literal(2), Literal(3)) | ||
|
|
||
| assertEquivalent(EqualTo(ifExp, Literal(4)), FalseLiteral) | ||
| assertEquivalent(EqualTo(ifExp, Literal(3)), EqualTo(ifExp, Literal(3))) | ||
| assertEquivalent(EqualTo(ifExp, Literal("4")), FalseLiteral) | ||
| assertEquivalent(EqualTo(ifExp, Literal("3")), EqualTo(ifExp, Literal(3))) | ||
|
|
||
| // Do not simplify if it contains non foldable expressions. | ||
| assertEquivalent(EqualTo(If(a === Literal(1), b, Literal(2)), Literal(3)), | ||
| EqualTo(If(a === Literal(1), b, Literal(2)), Literal(3))) | ||
| assertEquivalent( | ||
| EqualTo(If(a, b, Literal(2)), Literal(3)), | ||
| EqualTo(If(a, b, Literal(2)), Literal(3))) | ||
| val nonFoldable = If(NonFoldableLiteral(true), Literal(1), Literal(2)) | ||
|
||
| assertEquivalent(EqualTo(nonFoldable, Literal(1)), EqualTo(nonFoldable, Literal(1))) | ||
|
|
||
|
|
@@ -223,20 +224,19 @@ class SimplifyConditionalSuite extends PlanTest with ExpressionEvalHelper with P | |
|
|
||
| // Should not handle Null values. | ||
| assertEquivalent( | ||
| EqualTo(If(a === Literal(1), Literal(null, IntegerType), Literal(1)), Literal(2)), | ||
| EqualTo(If(a === Literal(1), Literal(null, IntegerType), Literal(1)), Literal(2))) | ||
| EqualTo(If(a, Literal(null, IntegerType), Literal(1)), Literal(2)), | ||
| EqualTo(If(a, Literal(null, IntegerType), Literal(1)), Literal(2))) | ||
| assertEquivalent( | ||
| EqualTo(If(a =!= Literal(1), Literal(1), Literal(2)), Literal(null, IntegerType)), | ||
| EqualTo(If(a =!= Literal(1), Literal(1), Literal(2)), Literal(null, IntegerType))) | ||
| EqualTo(If(!a, Literal(1), Literal(2)), Literal(null, IntegerType)), | ||
|
||
| EqualTo(If(!a, Literal(1), Literal(2)), Literal(null, IntegerType))) | ||
| assertEquivalent( | ||
| EqualTo(If(a === Literal(1), Literal(null, IntegerType), Literal(1)), Literal(1)), | ||
| EqualTo(If(a === Literal(1), Literal(null, IntegerType), Literal(1)), Literal(1))) | ||
| EqualTo(If(a, Literal(null, IntegerType), Literal(1)), Literal(1)), | ||
| EqualTo(If(a, Literal(null, IntegerType), Literal(1)), Literal(1))) | ||
| assertEquivalent( | ||
| EqualTo(If(a =!= Literal(1), Literal(null, IntegerType), Literal(1)), Literal(1)), | ||
| EqualTo(If(a =!= Literal(1), Literal(null, IntegerType), Literal(1)), Literal(1))) | ||
| EqualTo(If(!a, Literal(null, IntegerType), Literal(1)), Literal(1)), | ||
| EqualTo(If(!a, Literal(null, IntegerType), Literal(1)), Literal(1))) | ||
| assertEquivalent( | ||
| EqualTo(If(a =!= Literal(1), Literal(null, IntegerType), Literal(null, IntegerType)), | ||
| Literal(1)), | ||
| EqualTo(If(!a, Literal(null, IntegerType), Literal(null, IntegerType)), Literal(1)), | ||
| Literal(null, BooleanType)) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, let's don't test invalid expressions,
ifExp.dataTypeis int, not string.