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

    https://github.com/apache/spark/pull/22198#discussion_r212811422
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveHints.scala
 ---
    @@ -47,20 +49,39 @@ object ResolveHints {
        *
        * This rule must happen before common table expressions.
        */
    -  class ResolveBroadcastHints(conf: SQLConf) extends Rule[LogicalPlan] {
    +  class ResolveBroadcastHints(conf: SQLConf, catalog: SessionCatalog) 
extends Rule[LogicalPlan] {
         private val BROADCAST_HINT_NAMES = Set("BROADCAST", "BROADCASTJOIN", 
"MAPJOIN")
     
         def resolver: Resolver = conf.resolver
     
    -    private def applyBroadcastHint(plan: LogicalPlan, toBroadcast: 
Set[String]): LogicalPlan = {
    +    private def namePartsWithDatabase(nameParts: Seq[String]): Seq[String] 
= {
    +      if (nameParts.size == 1) {
    +        catalog.getCurrentDatabase +: nameParts
    +      } else {
    +        nameParts
    +      }
    +    }
    +
    +    private def matchedTableIdentifier(
    +        nameParts: Seq[String],
    +        tableIdent: IdentifierWithDatabase): Boolean = {
    +      val identifierList =
    +        tableIdent.database.getOrElse(catalog.getCurrentDatabase) :: 
tableIdent.identifier :: Nil
    +      
namePartsWithDatabase(nameParts).corresponds(identifierList)(resolver)
    --- End diff --
    
    This logic will make a regression (`plan1` in the below) in case of global 
temporary view. Please add the following test case into `GlobalTempViewSuite` 
and revise the logic to handle both cases correctly.
    
    ```scala
    test("broadcast hint on global temp view") {
        import org.apache.spark.sql.catalyst.plans.logical.{ResolvedHint, Join}
    
        spark.range(10).createGlobalTempView("v1")
        spark.range(10).createOrReplaceTempView("v2")
    
        val plan1 = sql(s"SELECT /*+ BROADCAST(v1) */ * FROM global_temp.v1, v2 
WHERE v1.id = v2.id")
          .queryExecution.optimizedPlan
        assert(plan1.asInstanceOf[Join].left.isInstanceOf[ResolvedHint])
        assert(!plan1.asInstanceOf[Join].right.isInstanceOf[ResolvedHint])
    
        val plan2 = sql(
          s"SELECT /*+ BROADCAST(global_temp.v1) */ * FROM global_temp.v1, v2 
WHERE v1.id = v2.id")
          .queryExecution.optimizedPlan
        assert(plan2.asInstanceOf[Join].left.isInstanceOf[ResolvedHint])
        assert(!plan2.asInstanceOf[Join].right.isInstanceOf[ResolvedHint])
      }
    ```


---

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

Reply via email to