Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11696#discussion_r56120228
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -354,59 +425,54 @@ class SQLBuilder(logicalPlan: LogicalPlan, 
sqlContext: SQLContext) extends Loggi
             //    +- Filter ...
             //        +- Aggregate ...
             //            +- MetastoreRelation default, src, None
    -        case plan @ Project(_, Filter(_, _: Aggregate)) => 
wrapChildWithSubquery(plan)
    +        case p @ Project(_, f @ Filter(_, _: Aggregate)) => p.copy(child = 
addSubquery(f))
     
    -        case w @ Window(_, _, _, Filter(_, _: Aggregate)) => 
wrapChildWithSubquery(w)
    +        case w @ Window(_, _, _, f @ Filter(_, _: Aggregate)) => 
w.copy(child = addSubquery(f))
     
    -        case plan @ Project(_,
    -          _: SubqueryAlias
    -            | _: Filter
    -            | _: Join
    -            | _: MetastoreRelation
    -            | OneRowRelation
    -            | _: LocalLimit
    -            | _: GlobalLimit
    -            | _: Sample
    -        ) => plan
    -
    -        case plan: Project => wrapChildWithSubquery(plan)
    +        case p: Project => p.copy(child = addSubqueryIfNeeded(p.child))
     
             // We will generate "SELECT ... FROM ..." for Window operator, so 
its child operator should
             // be able to put in the FROM clause, or we wrap it with a 
subquery.
    -        case w @ Window(_, _, _,
    -          _: SubqueryAlias
    -            | _: Filter
    -            | _: Join
    -            | _: MetastoreRelation
    -            | OneRowRelation
    -            | _: LocalLimit
    -            | _: GlobalLimit
    -            | _: Sample
    -        ) => w
    -
    -        case w: Window => wrapChildWithSubquery(w)
    -      }
    +        case w: Window => w.copy(child = addSubqueryIfNeeded(w.child))
     
    -      private def wrapChildWithSubquery(plan: UnaryNode): LogicalPlan = {
    -        val newChild = SubqueryAlias(SQLBuilder.newSubqueryName, 
plan.child)
    -        plan.withNewChildren(Seq(newChild))
    +        case j: Join => j.copy(
    +          left = addSubqueryIfNeeded(j.left),
    +          right = addSubqueryIfNeeded(j.right))
           }
         }
     
    -    object UpdateQualifiers extends Rule[LogicalPlan] {
    -      override def apply(tree: LogicalPlan): LogicalPlan = tree 
transformUp {
    -        case plan =>
    -          val inputAttributes = plan.children.flatMap(_.output)
    -          plan transformExpressions {
    -            case a: AttributeReference if 
!plan.producedAttributes.contains(a) =>
    -              val qualifier = inputAttributes.find(_ semanticEquals 
a).map(_.qualifiers)
    -              a.withQualifiers(qualifier.getOrElse(Nil))
    -          }
    +    private def needSubquery(plan: LogicalPlan): Boolean = plan match {
    --- End diff --
    
    maybe just inline this since it is used only once


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