-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19601] [SQL] Fix CollapseRepartition rule to preserve shuffle-enabled Repartition #16933
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 7 commits
7b4a9dd
7722781
f9483cb
0f95a6f
680c3af
5453ad4
4649af4
8306c49
379a15a
d69c5a1
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 |
|---|---|---|
|
|
@@ -32,47 +32,180 @@ class CollapseRepartitionSuite extends PlanTest { | |
|
|
||
| val testRelation = LocalRelation('a.int, 'b.int) | ||
|
|
||
|
|
||
| test("collapse two adjacent coalesces into one") { | ||
| // Always respects the top coalesces amd removes useless coalesce below coalesce | ||
| val query1 = testRelation | ||
| .coalesce(10) | ||
| .coalesce(20) | ||
|
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. hmm, I can see the argument.
Member
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. I think it would be better to respect the later input number, which is specified by users, for avoiding any surprise to users.
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. ok, agreed. |
||
| val query2 = testRelation | ||
| .coalesce(30) | ||
| .coalesce(20) | ||
|
|
||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val optimized2 = Optimize.execute(query2.analyze) | ||
|
|
||
| val correctAnswer = testRelation.coalesce(20).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer) | ||
| comparePlans(optimized2, correctAnswer) | ||
| } | ||
|
|
||
| test("collapse two adjacent repartitions into one") { | ||
| val query = testRelation | ||
| // Always respects the top repartition amd removes useless repartition below repartition | ||
| val query1 = testRelation | ||
| .repartition(10) | ||
| .repartition(20) | ||
| val query2 = testRelation | ||
| .repartition(30) | ||
| .repartition(20) | ||
|
|
||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer = testRelation.repartition(20).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer) | ||
| comparePlans(optimized2, correctAnswer) | ||
| } | ||
|
|
||
| test("coalesce above repartition") { | ||
| // Remove useless coalesce above repartition | ||
| val query1 = testRelation | ||
| .repartition(10) | ||
| .coalesce(20) | ||
|
|
||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val correctAnswer1 = testRelation.repartition(10).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer1) | ||
|
|
||
| // No change in this case | ||
| val query2 = testRelation | ||
| .repartition(30) | ||
| .coalesce(20) | ||
|
|
||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer2 = query2.analyze | ||
|
|
||
| comparePlans(optimized2, correctAnswer2) | ||
| } | ||
|
|
||
| test("repartition above coalesce") { | ||
| // Always respects the top repartition amd removes useless coalesce below repartition | ||
| val query1 = testRelation | ||
| .coalesce(10) | ||
| .repartition(20) | ||
| // Remove useless coalesce above repartition | ||
| val query2 = testRelation | ||
| .coalesce(30) | ||
| .repartition(20) | ||
|
|
||
| val optimized = Optimize.execute(query.analyze) | ||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val optimized2 = Optimize.execute(query2.analyze) | ||
|
|
||
| val correctAnswer = testRelation.repartition(20).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| comparePlans(optimized1, correctAnswer) | ||
| comparePlans(optimized2, correctAnswer) | ||
| } | ||
|
|
||
| test("collapse repartition and repartitionBy into one") { | ||
| val query = testRelation | ||
| test("repartitionBy above repartition") { | ||
| val query1 = testRelation | ||
| .repartition(10) | ||
| .distribute('a)(20) | ||
|
|
||
| val optimized = Optimize.execute(query.analyze) | ||
| val correctAnswer = testRelation.distribute('a)(20).analyze | ||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val correctAnswer1 = testRelation.distribute('a)(20).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer1) | ||
|
|
||
| val query2 = testRelation | ||
| .repartition(30) | ||
| .distribute('a)(20) | ||
|
|
||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer2 = testRelation.distribute('a)(20).analyze | ||
|
||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| comparePlans(optimized2, correctAnswer2) | ||
| } | ||
|
|
||
| test("collapse repartitionBy and repartition into one") { | ||
| val query = testRelation | ||
| test("repartitionBy above coalesce") { | ||
| val query1 = testRelation | ||
| .coalesce(10) | ||
| .distribute('a)(20) | ||
|
|
||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val correctAnswer1 = testRelation.distribute('a)(20).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer1) | ||
|
|
||
| val query2 = testRelation | ||
| .coalesce(20) | ||
| .distribute('a)(30) | ||
|
||
|
|
||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer2 = testRelation.distribute('a)(30).analyze | ||
|
|
||
| comparePlans(optimized2, correctAnswer2) | ||
| } | ||
|
|
||
| test("repartition above repartitionBy") { | ||
| val query1 = testRelation | ||
|
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. we can add a comment: |
||
| .distribute('a)(20) | ||
| .repartition(10) | ||
|
||
|
|
||
| val optimized = Optimize.execute(query.analyze) | ||
| val correctAnswer = testRelation.distribute('a)(10).analyze | ||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val correctAnswer1 = testRelation.distribute('a)(10).analyze | ||
|
||
|
|
||
| comparePlans(optimized1, correctAnswer1) | ||
|
|
||
| val query2 = testRelation | ||
| .distribute('a)(20) | ||
| .repartition(30) | ||
|
|
||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer2 = testRelation.distribute('a)(30).analyze | ||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| comparePlans(optimized2, correctAnswer2) | ||
| } | ||
|
|
||
| test("coalesce above repartitionBy") { | ||
| val query1 = testRelation | ||
| .distribute('a)(20) | ||
| .coalesce(10) | ||
|
|
||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val correctAnswer1 = testRelation.distribute('a)(20).coalesce(10).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer1) | ||
|
|
||
| val query2 = testRelation | ||
| .distribute('a)(20) | ||
| .coalesce(30) | ||
|
|
||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer2 = testRelation.distribute('a)(20).analyze | ||
|
|
||
| comparePlans(optimized2, correctAnswer2) | ||
| } | ||
|
|
||
| test("collapse two adjacent repartitionBys into one") { | ||
| val query = testRelation | ||
| val query1 = testRelation | ||
| .distribute('b)(10) | ||
| .distribute('a)(20) | ||
|
|
||
| val optimized = Optimize.execute(query.analyze) | ||
| val correctAnswer = testRelation.distribute('a)(20).analyze | ||
| val optimized1 = Optimize.execute(query1.analyze) | ||
| val correctAnswer1 = testRelation.distribute('a)(20).analyze | ||
|
|
||
| comparePlans(optimized1, correctAnswer1) | ||
|
|
||
| val query2 = testRelation | ||
| .distribute('b)(30) | ||
| .distribute('a)(20) | ||
|
|
||
| val optimized2 = Optimize.execute(query2.analyze) | ||
| val correctAnswer2 = testRelation.distribute('a)(20).analyze | ||
|
||
|
|
||
| comparePlans(optimized, correctAnswer) | ||
| comparePlans(optimized2, correctAnswer2) | ||
| } | ||
| } | ||
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.
does it conflict with sql coalesce by having it here?
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.
They are used for the test cases in catalyst package, in which Dataset APIs are not available. Thus, that is why we add these DSL for test cases