Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/14132#discussion_r71260158 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/catalyst/SQLBuilder.scala --- @@ -425,6 +452,49 @@ class SQLBuilder(logicalPlan: LogicalPlan) extends Logging { } } + /** + * Merge and move upward to the nearest Project. + * A broadcast hint comment is scattered into multiple nodes inside the plan, and the + * information of BroadcastHint resides its current position inside the plan. In order to + * reconstruct broadcast hint comment, we need to pack the information of BroadcastHint into + * Hint("BROADCAST", _, _) and collect them up by moving upward to the nearest Project node. + */ + object NormalizeBroadcastHint extends Rule[LogicalPlan] { + override def apply(plan: LogicalPlan): LogicalPlan = plan transformUp { + // Capture the broadcasted information and store it in Hint. + case BroadcastHint(child @ SubqueryAlias(_, Project(_, SQLTable(database, table, _, _)))) => + Hint("BROADCAST", Seq(table), child) + + // Nearest Project is found. + case p @ Project(_, Hint(_, _, _)) => p + + // Merge BROADCAST hints up to the nearest Project. + case Hint("BROADCAST", params1, h @ Hint("BROADCAST", params2, _)) => + h.copy(parameters = params1 ++ params2) + case j @ Join(h1 @ Hint("BROADCAST", p1, left), h2 @ Hint("BROADCAST", p2, right), _, _) => + h1.copy(parameters = p1 ++ p2, child = j.copy(left = left, right = right)) + + // Bubble up BROADCAST hints to the nearest Project. + case j @ Join(h @ Hint("BROADCAST", _, hintChild), _, _, _) => + h.copy(child = j.copy(left = hintChild)) + case j @ Join(_, h @ Hint("BROADCAST", _, hintChild), _, _) => + h.copy(child = j.copy(right = hintChild)) + case s @ SubqueryAlias(_, h @ Hint("BROADCAST", _, hintChild)) => + h.copy(child = s.copy(child = hintChild)) + case ll @ LocalLimit(_, h @ Hint("BROADCAST", _, hintChild)) => + h.copy(child = ll.copy(child = hintChild)) + case f @ Filter(_, h @ Hint("BROADCAST", _, hintChild)) => + h.copy(child = f.copy(child = hintChild)) + case a @ Aggregate(_, _, h @ Hint("BROADCAST", _, hintChild)) => + h.copy(child = a.copy(child = hintChild)) + case s @ Sort(_, _, h @ Hint("BROADCAST", _, hintChild)) => + h.copy(child = s.copy(child = hintChild)) + case g @ Generate(_, _, _, _, _, h @ Hint("BROADCAST", _, hintChild)) => + h.copy(child = g.copy(child = hintChild)) + // Set operation is not allowed to be across. UNION/INTERCEPT/EXCEPT --- End diff -- Your reply is different from the comment in the code.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org