-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-8300] DataFrame hint for broadcast join. #6751
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ package org.apache.spark.sql.execution | |
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.planning._ | ||
| import org.apache.spark.sql.catalyst.plans._ | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.catalyst.plans.logical.{BroadcastHint, LogicalPlan} | ||
| import org.apache.spark.sql.catalyst.plans.physical._ | ||
| import org.apache.spark.sql.columnar.{InMemoryColumnarTableScan, InMemoryRelation} | ||
| import org.apache.spark.sql.execution.{DescribeCommand => RunnableDescribeCommand} | ||
|
|
@@ -52,6 +52,18 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Matches a plan whose output should be small enough to be used in broadcast join. | ||
| */ | ||
| object CanBroadcast { | ||
|
Contributor
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. @marmbrus is this what you had in mind?
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. Yep! |
||
| def unapply(plan: LogicalPlan): Option[LogicalPlan] = plan match { | ||
| case BroadcastHint(p) => Some(p) | ||
| case p if sqlContext.conf.autoBroadcastJoinThreshold > 0 && | ||
| p.statistics.sizeInBytes <= sqlContext.conf.autoBroadcastJoinThreshold => Some(p) | ||
| case _ => None | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Uses the ExtractEquiJoinKeys pattern to find joins where at least some of the predicates can be | ||
| * evaluated by matching hash keys. | ||
|
|
@@ -80,15 +92,11 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
| } | ||
|
|
||
| def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
| case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, right) | ||
| if sqlContext.conf.autoBroadcastJoinThreshold > 0 && | ||
| right.statistics.sizeInBytes <= sqlContext.conf.autoBroadcastJoinThreshold => | ||
| case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, CanBroadcast(right)) => | ||
| makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, joins.BuildRight) | ||
|
|
||
| case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, right) | ||
| if sqlContext.conf.autoBroadcastJoinThreshold > 0 && | ||
| left.statistics.sizeInBytes <= sqlContext.conf.autoBroadcastJoinThreshold => | ||
| makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, joins.BuildLeft) | ||
| case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, CanBroadcast(left), right) => | ||
| makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, joins.BuildLeft) | ||
|
|
||
| // If the sort merge join option is set, we want to use sort merge join prior to hashjoin | ||
| // for now let's support inner join first, then add outer join | ||
|
|
@@ -329,6 +337,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
| case e @ EvaluatePython(udf, child, _) => | ||
| BatchPythonEvaluation(udf, e.output, planLater(child)) :: Nil | ||
| case LogicalRDD(output, rdd) => PhysicalRDD(output, rdd) :: Nil | ||
| case BroadcastHint(child) => apply(child) | ||
| case _ => Nil | ||
| } | ||
| } | ||
|
|
||
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.
Could we just have this be
StatisticsHintand override the statistics? I'm afraid that we are going to forget to add cases in the future as we broadcast more type of joins.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.
that sounds good.
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.
I'm thinking about this more and actually maybe what we want to do is have this specific node, and a pattern that recognizes
canBroadcast. This pattern can check either for a small enough size or this hint and we can use that anywhere we are planning a broadcast operator. The reasoning is that messing with statistics could have other consequences.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.
+1
Add specific node is also doable, probably the node can be named like
HintinLogicalPlan, and could be more thanbroadcast, likeuniq_keyetc.Any idea?