-
Notifications
You must be signed in to change notification settings - Fork 264
perf: Add experimental feature to replace SortMergeJoin with ShuffledHashJoin #1007
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a1d04f5
experiment
andygrove 598735e
fix and add credit
andygrove d55f2ea
disable by default and make internal
andygrove e3313bd
remove sort
andygrove a0d1381
minor optimization
andygrove 948f2c0
minor optimization
andygrove fd87412
remove unused import
andygrove 99eca10
disable feature by default
andygrove 1d5b58d
fix dockerfile
andygrove 1a5de4e
Add section to tuning guide
andygrove 7cce6a5
update benchmarking guide
andygrove 8f5d440
Merge remote-tracking branch 'apache/main' into replace-smj
andygrove 7ce8726
Revert "chore: Reserve memory for native shuffle writer per partition…
andygrove 26f9a4f
mark feature as experimental and explain risks
andygrove 27a02af
upmerge
andygrove 63ce71c
workaround for TPC-DS q14 hanging on a RightSemi join
andygrove 60d1028
revert a change
andygrove 662d0de
remove debug logging:
andygrove 6ed01c1
format
andygrove 1073517
add link to tuning guide
andygrove 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
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
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
66 changes: 66 additions & 0 deletions
66
spark/src/main/scala/org/apache/comet/rules/RewriteJoin.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,66 @@ | ||
| /* | ||
| * 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.comet.rules | ||
|
|
||
| import org.apache.spark.sql.catalyst.optimizer.{BuildLeft, BuildRight, BuildSide, JoinSelectionHelper} | ||
| import org.apache.spark.sql.catalyst.plans.JoinType | ||
| import org.apache.spark.sql.execution.{SortExec, SparkPlan} | ||
| import org.apache.spark.sql.execution.joins.{ShuffledHashJoinExec, SortMergeJoinExec} | ||
|
|
||
| /** | ||
| * Adapted from equivalent rule in Apache Gluten. | ||
| * | ||
| * This rule replaces [[SortMergeJoinExec]] with [[ShuffledHashJoinExec]]. | ||
| */ | ||
| object RewriteJoin extends JoinSelectionHelper { | ||
|
|
||
| private def getBuildSide(joinType: JoinType): Option[BuildSide] = { | ||
| if (canBuildShuffledHashJoinRight(joinType)) { | ||
| Some(BuildRight) | ||
| } else if (canBuildShuffledHashJoinLeft(joinType)) { | ||
| Some(BuildLeft) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| private def removeSort(plan: SparkPlan) = plan match { | ||
| case _: SortExec => plan.children.head | ||
| case _ => plan | ||
| } | ||
|
|
||
| def rewrite(plan: SparkPlan): SparkPlan = plan match { | ||
| case smj: SortMergeJoinExec => | ||
| getBuildSide(smj.joinType) match { | ||
| case Some(buildSide) => | ||
| ShuffledHashJoinExec( | ||
| smj.leftKeys, | ||
| smj.rightKeys, | ||
| smj.joinType, | ||
| buildSide, | ||
| smj.condition, | ||
| removeSort(smj.left), | ||
| removeSort(smj.right), | ||
| smj.isSkewJoin) | ||
| case _ => plan | ||
| } | ||
| case _ => plan | ||
| } | ||
| } |
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.
unrelated, but ran into this hard-coded version number during testing