-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12594] [SQL] Outer Join Elimination by Filter Conditions #10542
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
2f6c80d
Merge remote-tracking branch 'upstream/master' into outerJoinElimination
gatorsmile 90576aa
outer join conversion
gatorsmile 5adec63
[SPARK-10359][PROJECT-INFRA] Multiple fixes to dev/test-dependencies.…
JoshRosen 192ab19
added test cases.
gatorsmile c9dbfcc
[SPARK-11743][SQL] Move the test for arrayOfUDT
viirya a59a357
[SPARK-3873][MLLIB] Import order fixes.
ad5b7cf
[SPARK-12409][SPARK-12387][SPARK-12391][SQL] Refactor filter pushdown…
viirya c04b53b
renaming
gatorsmile 01a2986
[SPARK-12592][SQL][TEST] Don't mute Spark loggers in TestHive.reset()
liancheng 6c20b3c
Disable test-dependencies.sh.
rxin 0da7bd5
[SPARK-12286][SPARK-12290][SPARK-12294][SPARK-12284][SQL] always outp…
44ee920
Revert "[SPARK-12286][SPARK-12290][SPARK-12294][SPARK-12284][SQL] alw…
rxin 970635a
[SPARK-12362][SQL][WIP] Inline Hive Parser
hvanhovell 94f7a12
[SPARK-10180][SQL] JDBC datasource are not processing EqualNullSafe f…
HyukjinKwon 15bd736
[SPARK-12481][CORE][STREAMING][SQL] Remove usage of Hadoop deprecated…
srowen 65f9125
extend the condition to cover more cases in non null predicates.
gatorsmile 513e3b0
[SPARK-12599][MLLIB][SQL] Remove the use of callUDF in MLlib
rxin 6c5bbd6
Revert "Revert "[SPARK-12286][SPARK-12290][SPARK-12294][SPARK-12284][…
rxin 9398644
added three more expressions: and, or and not
gatorsmile 0bb07cb
style fix.
gatorsmile c5ff632
support non-local predicates and bug fix.
gatorsmile c3d5056
[SPARK-12327][SPARKR] fix code for lintr warning for commented code
felixcheung ee29dd2
scala style fix.
gatorsmile c82924d
[SPARK-12533][SQL] hiveContext.table() throws the wrong exception
thomastechs 7b92922
Update MimaExcludes now Spark 1.6 is in Maven.
rxin b8410ff
[SPARK-12537][SQL] Add option to accept quoting of all character back…
Cazen 13dab9c
[SPARK-12611][SQL][PYSPARK][TESTS] Fix test_infer_schema_to_local
holdenk 7b7ea90
outer join conversion
gatorsmile 7558e70
added test cases.
gatorsmile d3cbf46
renaming
gatorsmile 2535cb1
extend the condition to cover more cases in non null predicates.
gatorsmile 6c3f4b0
added three more expressions: and, or and not
gatorsmile fcd757c
style fix.
gatorsmile 5bc7f52
support non-local predicates and bug fix.
gatorsmile 34a0056
scala style fix.
gatorsmile ee7db1a
code refactoring and code merge
gatorsmile 63d5d62
Merge remote-tracking branch 'origin/outerJoinConversion' into outerJ…
gatorsmile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...yst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/OuterJoinConversionSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.optimizer | ||
|
|
||
| import org.apache.spark.sql.catalyst.analysis.EliminateSubQueries | ||
| import org.apache.spark.sql.catalyst.plans._ | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.rules._ | ||
| import org.apache.spark.sql.catalyst.dsl.plans._ | ||
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
|
|
||
| class OuterJoinConversionSuite extends PlanTest { | ||
| object Optimize extends RuleExecutor[LogicalPlan] { | ||
| val batches = | ||
| Batch("Subqueries", Once, | ||
| EliminateSubQueries) :: | ||
| Batch("OuterJoinConversion", Once, | ||
| OuterJoinConversion, | ||
| PushPredicateThroughJoin) :: Nil | ||
| } | ||
|
|
||
| val testRelation = LocalRelation('a.int, 'b.int, 'c.int) | ||
| val testRelation1 = LocalRelation('d.int, 'e.int, 'f.int) | ||
|
|
||
| test("joins: full outer to inner") { | ||
| val x = testRelation.subquery('x) | ||
| val y = testRelation1.subquery('y) | ||
|
|
||
| val originalQuery = | ||
| x.join(y, FullOuter, Option("x.a".attr === "y.d".attr)) | ||
| .where("x.b".attr >= 1 && "y.d".attr >= 2) | ||
|
|
||
| val optimized = Optimize.execute(originalQuery.analyze) | ||
| val left = testRelation.where('b >= 1) | ||
| val right = testRelation1.where('d >= 2) | ||
| val correctAnswer = | ||
| left.join(right, Inner, Option("a".attr === "d".attr)).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| } | ||
|
|
||
| test("joins: full outer to right") { | ||
| val x = testRelation.subquery('x) | ||
| val y = testRelation1.subquery('y) | ||
|
|
||
| val originalQuery = | ||
| x.join(y, FullOuter, Option("x.a".attr === "y.d".attr)).where("y.d".attr > 2) | ||
|
|
||
| val optimized = Optimize.execute(originalQuery.analyze) | ||
| val left = testRelation | ||
| val right = testRelation1.where('d > 2) | ||
| val correctAnswer = | ||
| left.join(right, RightOuter, Option("a".attr === "d".attr)).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| } | ||
|
|
||
| test("joins: full outer to left") { | ||
| val x = testRelation.subquery('x) | ||
| val y = testRelation1.subquery('y) | ||
|
|
||
| val originalQuery = | ||
| x.join(y, FullOuter, Option("x.a".attr === "y.d".attr)).where("x.a".attr <=> 2) | ||
|
|
||
| val optimized = Optimize.execute(originalQuery.analyze) | ||
| val left = testRelation.where('a <=> 2) | ||
| val right = testRelation1 | ||
| val correctAnswer = | ||
| left.join(right, LeftOuter, Option("a".attr === "d".attr)).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| } | ||
|
|
||
| test("joins: right to inner") { | ||
| val x = testRelation.subquery('x) | ||
| val y = testRelation1.subquery('y) | ||
|
|
||
| val originalQuery = | ||
| x.join(y, RightOuter, Option("x.a".attr === "y.d".attr)).where("x.b".attr > 2) | ||
|
|
||
| val optimized = Optimize.execute(originalQuery.analyze) | ||
| val left = testRelation.where('b > 2) | ||
| val right = testRelation1 | ||
| val correctAnswer = | ||
| left.join(right, Inner, Option("a".attr === "d".attr)).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| } | ||
|
|
||
| test("joins: left to inner") { | ||
| val x = testRelation.subquery('x) | ||
| val y = testRelation1.subquery('y) | ||
|
|
||
| val originalQuery = | ||
| x.join(y, LeftOuter, Option("x.a".attr === "y.d".attr)).where("y.e".attr.isNotNull) | ||
|
|
||
| val optimized = Optimize.execute(originalQuery.analyze) | ||
| val left = testRelation | ||
| val right = testRelation1.where('e.isNotNull) | ||
| val correctAnswer = | ||
| left.join(right, Inner, Option("a".attr === "d".attr)).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is there a better name for this? this is a form of strength reduction right? I don't know if there is a better term in the database land. Can you look into postgres source code and see what they call this?
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.
You are right.
OuterJoinEliminationmight sound better. Let me rename it today.Since
full outerisunion distinctofleft outerandright outer, we are removingright outerfromfull outerwhen conversion fromfull outertoleft outer.