Github user dongjoon-hyun commented on a diff in the pull request:
https://github.com/apache/spark/pull/14132#discussion_r71202124
--- 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.
--- End diff --
Thanks. I added `GlobalLimit`, too. It seems my mistake during removing the
operator not allowed in SQLBuilder. When I develop Optimizers, I frequently
asked to use white-list approach. I hope to keep this style if you are okay.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]