Uh oh!
There was an error while loading. Please reload this page.
[SPARK-12161][SQL] Ignore order of predicates in cache matching - #10163
[SPARK-12161][SQL] Ignore order of predicates in cache matching#10163codingjaguar wants to merge 26 commits into
Conversation
refactor cleanArgs so that we can reuse cleanExpression().
cloud-fan
commented
Dec 7, 2015
This is a great feature! Can we implement it in individual expressions instead of centralizing them in |
codingjaguar
commented
Dec 7, 2015
Thanks for giving feedback! We think it would be nice to support all commutative operators in |
liancheng
commented
Dec 8, 2015
ok to test |
SparkQA
commented
Dec 8, 2015
Test build #47328 has finished for PR 10163 at commit
|
SparkQA
commented
Dec 8, 2015
Test build #47342 has finished for PR 10163 at commit
|
SparkQA
commented
Dec 8, 2015
Test build #47364 has finished for PR 10163 at commit
|
There was a problem hiding this comment.
how about we just change this to:
cleanRight.zip(cleanArgs).forall {
case (e1: Expression, e2: Expression) => e1 semanticEquals e2 caes (a1, a2) => a1 == a2
}
then we can just improve Expression.sentaicEquals
cloud-fan
commented
Dec 9, 2015
How about something like |
windscope
commented
Dec 9, 2015
To improve semanticEquals, we tried to implement a template function |
codingjaguar
commented
Dec 9, 2015
In last change we deleted |
There was a problem hiding this comment.
Sorry I didn't clarify it clearly. I mean we can override semanticEquals in concrete expressions like Or, And, etc. And we don't need to support all commutative operators at once, you can only finish the predicates parts in this PR and open follow-up PRs for other parts(like Add, Multiply). Let's do it step-by-step :)
SparkQA
commented
Dec 9, 2015
Test build #47419 has finished for PR 10163 at commit
|
codingjaguar
commented
Dec 9, 2015
We updated |
SparkQA
commented
Dec 9, 2015
Test build #47446 has finished for PR 10163 at commit
|
SparkQA
commented
Dec 10, 2015
Test build #47452 has finished for PR 10163 at commit
|
There was a problem hiding this comment.
Sorry I may missed something here, can we just write:
override def semanticEquals(other: Expression): Boolean = other match {
case And(otherLeft, otherRight) =>
(left.semanticEquals(otherLeft) && right.semanticEquals(otherRight)) ||
(left.semanticEquals(otherRight) && right.semanticEquals(otherLeft))
case _ => false
}
There was a problem hiding this comment.
Consider this examplee1 = And(a, And(b, c))e2 = And(And(a,b), c))
They are semantically equivalent, but will return false in your code.splitConjunctivePredicates will crunch the expression tree into a sequence of (a, b, c).
There was a problem hiding this comment.
ah I see, this makes sense.
But I think a better way is to add an optimization rule to turn all predicates into CNF, before we begin to check the semantic, or it will be hard to cover all cases like a || (b && c) == (a || b) && (a || c)
cc @liancheng
AmplabJenkins
commented
May 23, 2016
Can one of the admins verify this patch? |
rxin
commented
Jun 15, 2016
Thanks for the pull request. I'm going through a list of pull requests to cut them down since the sheer number is breaking some of the tooling we have. Due to lack of activity on this pull request, I'm going to push a commit to close it. Feel free to reopen it or create a new one. |
This PR improves
LogicalPlan.sameResultso that semantically equivalent queries with different order of predicates are still matched.Consider an example:
Query 1: CACHE TABLE first AS SELECT * FROM table A where A.id >100 AND A.id < 200;
Query 2: SELECT * FROM table A where A.id < 200 AND A.id > 100;
Currently in SparkSQL, Query 2 cannot utilize the cache result of query 1, although query 1 and query 2 are the same if ignoring the order of the predicates.
We modified the compare function
LogicalPlan.sameResult. The idea is to split the condition of filter into a sequence of expressions and wrap it into a set. Now we can easily compare the sets rather than literally compare the conditions, thus ignoring the order of the predicates.