Github user dongjoon-hyun commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14132#discussion_r71463337
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/catalyst/SQLBuilder.scala ---
    @@ -425,6 +449,44 @@ 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))
    +
    +        // Other UnaryNodes are bypassed.
    +        case u: UnaryNode
    +          if u.child.isInstanceOf[Hint] && 
u.child.asInstanceOf[Hint].name.equals("BROADCAST") =>
    --- End diff --
    
    Sure.


---
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

Reply via email to