Uh oh!
There was an error while loading. Please reload this page.
[SPARK-4937][SQL] Adding optimization to simplify the And, Or condition in spark sql - #3778
[SPARK-4937][SQL] Adding optimization to simplify the And, Or condition in spark sql#3778scwf wants to merge 9 commits into
Conversation
SparkQA
commented
Dec 23, 2014
Test build #24738 has started for PR 3778 at commit
|
SparkQA
commented
Dec 23, 2014
Test build #24738 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Dec 23, 2014
Test FAILed. |
SparkQA
commented
Dec 23, 2014
Test build #24739 has started for PR 3778 at commit
|
SparkQA
commented
Dec 23, 2014
Test build #24739 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Dec 23, 2014
Test FAILed. |
liancheng
commented
Dec 23, 2014
Hey @scwf, I'm kinda lost in all the predicates provided in the PR description... Would you mind to provide several simpler cases to illustrate what kind of optimizations this PR enables? I guess essentially the second case is this:
Is it correct? |
scwf
commented
Dec 24, 2014
Yes, correct, later i will give a detail description for this:) |
scwf
commented
Dec 24, 2014
change to WIP, todos: |
liancheng
commented
Dec 24, 2014
@scwf These optimizations are useful, particularly the one that eliminates common predicates. Thanks for bringing them up! However, the implementation in this PR is really over complicated... I opened #3784 for a simpler version. For the numeric comparisons, I think we can first cast all numeric comparisons to |
SparkQA
commented
Dec 24, 2014
Test build #24768 has started for PR 3778 at commit
|
SparkQA
commented
Dec 24, 2014
Test build #24773 has started for PR 3778 at commit
|
SparkQA
commented
Dec 24, 2014
Test build #24768 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Dec 24, 2014
Test FAILed. |
SparkQA
commented
Dec 24, 2014
Test build #24773 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Dec 24, 2014
Test FAILed. |
SparkQA
commented
Dec 25, 2014
Test build #24804 has started for PR 3778 at commit
|
SparkQA
commented
Dec 25, 2014
Test build #24804 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Dec 25, 2014
Test PASSed. |
There was a problem hiding this comment.
Usually similar deeply nested if statements can be refactored into carefully organized pattern matches. Using pattern matching also frees you from helper methods like .isLess and isLessEquals, thus ExpressionCookies won't be necessary.
There was a problem hiding this comment.
Get it, actually i have recognized this. but the case here really complex...:)
I am trying to refactory this
scwf
commented
Dec 30, 2014
Hi, @marmbrus this is a more complete version than #3784 and @liancheng told me he will close #3784 in favor of this PR, but now you have merged #3784. So can you revert that one or Maybe should i change this with newly master branch? |
marmbrus
commented
Dec 30, 2014
Oh I see, sorry that was not clear from the discussion. I think it would be best to do this as an augmentation to what is already merged in. |
scwf
commented
Dec 30, 2014
Sure, updated! |
SparkQA
commented
Dec 30, 2014
Test build #24917 has started for PR 3778 at commit
|
SparkQA
commented
Dec 31, 2014
Test build #24917 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Dec 31, 2014
Test PASSed. |
scwf
commented
Jan 10, 2015
@marmbrus, any comments here? i think this is ok to go |
There was a problem hiding this comment.
Nit: the indenting is off here.
marmbrus
commented
Jan 11, 2015
This looks good to me. @liancheng have you looked this over too? |
SparkQA
commented
Jan 11, 2015
Test build #25368 has started for PR 3778 at commit
|
SparkQA
commented
Jan 11, 2015
Test build #25368 has finished for PR 3778 at commit
|
AmplabJenkins
commented
Jan 11, 2015
Test PASSed. |
scwf
commented
Jan 13, 2015
hey @liancheng, any other comments here? |
liancheng
commented
Jan 13, 2015
Sorry for the late reply, this LGTM, thanks! |
scwf
commented
Jan 14, 2015
Thanks, @marmbrus this should be ready to go. |
marmbrus
commented
Jan 16, 2015
Thanks! Merged to master. |
There was a problem hiding this comment.
I know this has been merged, but can you submit another PR to add comments explaining how this works? I'm afraid this block of code is beyond a normal engineer's capability to understand without spending hours staring at it. Thanks.
…nSimplification` Follow up of #3778 /cc rxin Author: scwf <wangfei1@huawei.com> Closes#4086 from scwf/commentforspark-4937 and squashes the following commits: aaf89f6 [scwf] code style issue 2d3406e [scwf] added comment for spark-4937
Adding optimization to simplify the And/Or condition in spark sql.
There are two kinds of Optimization
1 Numeric condition optimization, such as:
a < 3 && a > 5 ---- False
a < 1 || a > 0 ---- True
a > 3 && a > 5 => a > 5
(a < 2 || b > 5) && a < 2 => a < 2
2 optimizing the some query from a cartesian product into equi-join, such as this sql (one of hive-testbench):
It has a repeated expression in Or, so we can optimize it by

(a && b) || (a && c) = a && (b || c)Before optimization, this sql hang in my locally test, and the physical plan is:
After optimization, this sql run successfully in 20+ seconds, and its physical plan is:

This PR focus on the second optimization and some simple ones of the first. For complex Numeric condition optimization, I will make a follow up PR.