spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dongjoon-hyun <...@git.apache.org>
Subject [GitHub] spark pull request #14132: [SPARK-16475][SQL] Broadcast Hint for SQL Queries
Date Thu, 21 Jul 2016 12:16:46 GMT
Github user dongjoon-hyun commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14132#discussion_r71694195
  
    --- 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))
    --- End diff --
    
    Here is the candidate. Since we cannot take advantage of `case` statement, I added a function
for that.
    ```
    private def isBroadcastHint(logicalPlan: LogicalPlan): Boolean =
        logicalPlan.isInstanceOf[Hint] && logicalPlan.asInstanceOf[Hint].name.equals("BRAODCAST")
    
    ...
    case j: Join if j.children.exists(isBroadcastHint) =>
      val newChildren =
        j.children.map(x => if (isBroadcastHint(x)) x.asInstanceOf[Hint].child else x)
      Hint("BROADCAST",
        j.children.filter(isBroadcastHint).map(_.asInstanceOf[Hint]).flatMap(_.parameters),
        j.copy(left = newChildren(0), right = newChildren(1)))
    ```


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message