-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12503] [SQL] Pushing Limit Through Union All #10451
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 all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
01e4cdf
Merge remote-tracking branch 'upstream/master'
gatorsmile 6835704
Merge remote-tracking branch 'upstream/master'
gatorsmile 9180687
Merge remote-tracking branch 'upstream/master'
gatorsmile b38a21e
SPARK-11633
gatorsmile d2b84af
Merge remote-tracking branch 'upstream/master' into joinMakeCopy
gatorsmile fda8025
Merge remote-tracking branch 'upstream/master'
gatorspark ac0dccd
Merge branch 'master' of https://github.com/gatorsmile/spark
gatorspark 6e0018b
Merge remote-tracking branch 'upstream/master'
0546772
converge
gatorsmile b37a64f
converge
gatorsmile 661260b
Merge remote-tracking branch 'upstream/master'
gatorsmile 2dfa0fd
Merge remote-tracking branch 'upstream/master'
gatorsmile d929d9b
Merge remote-tracking branch 'upstream/master'
gatorsmile 4070d2f
Merge remote-tracking branch 'upstream/master'
gatorsmile 38dcfb2
Merge remote-tracking branch 'upstream/master'
gatorsmile cb3fc83
Merge remote-tracking branch 'upstream/master'
gatorsmile 8dbacc7
Merge remote-tracking branch 'upstream/master'
gatorsmile 41b9172
Merge remote-tracking branch 'upstream/master'
gatorsmile 56fd782
union limit pushdown.
gatorsmile b5ac8d7
Merge remote-tracking branch 'upstream/master' into unionLimit
gatorsmile 77105e3
combine the limits.
gatorsmile 7f25d91
update the comments.
gatorsmile ae59f42
add a stop flag.
gatorsmile 3ccf3bd
fixed the build failure.
gatorsmile 004ed66
revert the changes back.
gatorsmile 6998ec9
added limitedNumRows into the logicalPlan
gatorsmile 09a5672
changed limitedNumRows to maxRows
gatorsmile 358d62e
address the comments.
gatorsmile 2823a57
addressed comments.
gatorsmile 10d570c
Merge remote-tracking branch 'upstream/master'
gatorsmile cfbeea7
Merge branch 'unionLimit' into unionLimit2
gatorsmile ca5c104
addressed comments.
gatorsmile 56f0c16
address the comments.
gatorsmile 62d5cbe
update the comment.
gatorsmile 7cf955f
update the comment.
gatorsmile 7899312
Merge remote-tracking branch 'upstream/master' into unionLimit2
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
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
76 changes: 76 additions & 0 deletions
76
...catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/PushdownLimitsSuite.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,76 @@ | ||
| /* | ||
| * 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.PlanTest | ||
| 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 PushdownLimitsSuite extends PlanTest { | ||
| object Optimize extends RuleExecutor[LogicalPlan] { | ||
| val batches = | ||
| Batch("Subqueries", Once, | ||
| EliminateSubQueries) :: | ||
| Batch("Push Down Limit", Once, | ||
| PushDownLimit, | ||
| CombineLimits, | ||
| ConstantFolding, | ||
| BooleanSimplification) :: Nil | ||
| } | ||
|
|
||
| val testRelation = LocalRelation('a.int, 'b.int, 'c.int) | ||
| val testRelation2 = LocalRelation('d.int, 'e.int, 'f.int) | ||
|
|
||
| test("Union: limit to each side") { | ||
| val unionQuery = Union(testRelation, testRelation2).limit(1) | ||
| val unionOptimized = Optimize.execute(unionQuery.analyze) | ||
| val unionCorrectAnswer = | ||
| Limit(1, Union(testRelation.limit(1), testRelation2.limit(1))).analyze | ||
| comparePlans(unionOptimized, unionCorrectAnswer) | ||
| } | ||
|
|
||
| test("Union: limit to each side with the new limit number") { | ||
| val testLimitUnion = Union(testRelation, testRelation2.limit(3)) | ||
| val unionQuery = testLimitUnion.limit(1) | ||
| val unionOptimized = Optimize.execute(unionQuery.analyze) | ||
| val unionCorrectAnswer = | ||
| Limit(1, Union(testRelation.limit(1), testRelation2.limit(1))).analyze | ||
| comparePlans(unionOptimized, unionCorrectAnswer) | ||
| } | ||
|
|
||
| test("Union: no limit to both sides if children having smaller limit values") { | ||
| val testLimitUnion = Union(testRelation.limit(1), testRelation2.select('d).limit(1)) | ||
| val unionQuery = testLimitUnion.limit(2) | ||
| val unionOptimized = Optimize.execute(unionQuery.analyze) | ||
| val unionCorrectAnswer = | ||
| Limit(2, Union(testRelation.limit(1), testRelation2.select('d).limit(1))).analyze | ||
| comparePlans(unionOptimized, unionCorrectAnswer) | ||
| } | ||
|
|
||
| test("Union: limit to each sides if children having larger limit values") { | ||
| val testLimitUnion = Union(testRelation.limit(3), testRelation2.select('d).limit(4)) | ||
| val unionQuery = testLimitUnion.limit(2) | ||
| val unionOptimized = Optimize.execute(unionQuery.analyze) | ||
| val unionCorrectAnswer = | ||
| Limit(2, Union(testRelation.limit(2), testRelation2.select('d).limit(2))).analyze | ||
| comparePlans(unionOptimized, unionCorrectAnswer) | ||
| } | ||
| } |
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.
Specify that any operator that a
Limitcan be pushed passed should override this function.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.
And, thus, we should fix
Projecttoo.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.
Fixed. Thanks!
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.
Actually we will push down
ProjectthroughLimitinColumnPruning.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.
Yeah, we need to override the function in both directions. Let me update the comments. Thanks!
The value of
maxRowsis used for the Project's parent or ancestor nodes that could be anotherLimit.