-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-20350] Add optimization rules to apply Complementation Laws. #17650
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 all commits
1abf691
b557165
688b2f0
5317dd4
ade7255
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import org.apache.spark.sql.catalyst.plans.PlanTest | |
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.rules._ | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.Row | ||
|
|
||
| class BooleanSimplificationSuite extends PlanTest with PredicateHelper { | ||
|
|
||
|
|
@@ -42,6 +43,16 @@ class BooleanSimplificationSuite extends PlanTest with PredicateHelper { | |
|
|
||
| val testRelation = LocalRelation('a.int, 'b.int, 'c.int, 'd.string) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding another boolean column? Our filter conditions are not allowed to accept the non-boolean predicates |
||
|
|
||
| val testRelationWithData = LocalRelation.fromExternalRows( | ||
| testRelation.output, Seq(Row(1, 2, 3, "abc")) | ||
| ) | ||
|
|
||
| private def checkCondition(input: Expression, expected: LogicalPlan): Unit = { | ||
| val plan = testRelationWithData.where(input).analyze | ||
| val actual = Optimize.execute(plan) | ||
| comparePlans(actual, expected) | ||
| } | ||
|
|
||
| private def checkCondition(input: Expression, expected: Expression): Unit = { | ||
| val plan = testRelation.where(input).analyze | ||
| val actual = Optimize.execute(plan) | ||
|
|
@@ -160,4 +171,12 @@ class BooleanSimplificationSuite extends PlanTest with PredicateHelper { | |
| testRelation.where('a > 2 || ('b > 3 && 'b < 5))) | ||
| comparePlans(actual, expected) | ||
| } | ||
|
|
||
| test("Complementation Laws") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about double negation ? ie.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really required for this PR? |
||
| checkCondition('a && !'a, testRelation) | ||
| checkCondition(!'a && 'a, testRelation) | ||
|
|
||
| checkCondition('a || !'a, testRelationWithData) | ||
| checkCondition(!'a || 'a, testRelationWithData) | ||
| } | ||
| } | ||
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.
Logically it feels like duplication of code from line 156 ... but unfortunately
Notis not smart enough to realise that. I think if you override thesemanticEqualsinNotthen you should be able to get rid of this line. The advantage being we would make the expression smart enough to figure this out by itself rather than handling this in outside code (which is possibly more places in the code).Same applies for line 159.
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.
I meant something like this for
Not: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.
do we need this?
Not(Not(a))will be simplified toa