spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-12705] [SQL] AnalysisException: Sorting...
Date Mon, 11 Jan 2016 06:20:21 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10678#discussion_r49292315
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
    @@ -521,16 +521,31 @@ class Analyzer(
        */
       object ResolveSortReferences extends Rule[LogicalPlan] {
         def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
    -      case s @ Sort(ordering, global, p @ Project(projectList, child))
    -          if !s.resolved && p.resolved =>
    -        val (newOrdering, missing) = resolveAndFindMissing(ordering, p, child)
    +      case s @ Sort(_, _, p @ Project(_, _)) if !s.resolved && p.resolved =>
    +        val (newOrdering, missing, newChild): (Seq[SortOrder], Seq[Attribute], LogicalPlan)
=
    +          p.child match {
    +            // Case 1: when WINDOW functions are used in the SELECT clause.
    +            //   Example: SELECT sum(col1) OVER() FROM table1 ORDER BY col2
    +            case p1 @ Project(_, w @ Window(_, _, _, _, p2: Project)) =>
    +              val (newOrdering, missingAttrs) = resolveAndFindMissing(s.order, p2, p2.child)
    +              (newOrdering, missingAttrs,
    +                Project(p1.projectList ++ missingAttrs,
    +                  Window(w.projectList ++ missingAttrs,
    +                    w.windowExpressions, w.partitionSpec, w.orderSpec,
    +                    Project(p2.projectList ++ missingAttrs, p2.child))))
    +            // Case 2: the other cases
    +            //   Example: SELECT col1 FROM table1 ORDER BY col2
    +            case _ =>
    +              val (newOrdering, missingAttrs) = resolveAndFindMissing(s.order, p, p.child)
    +              (newOrdering, missingAttrs, p.child)
    +        }
     
             // If this rule was not a no-op, return the transformed plan, otherwise return
the original.
             if (missing.nonEmpty) {
               // Add missing attributes and then project them away after the sort.
               Project(p.output,
    -            Sort(newOrdering, global,
    -              Project(projectList ++ missing, child)))
    +            Sort(newOrdering, s.global,
    --- End diff --
    
    Should we continue to add the missing attributes here until it can be resolved?


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