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

    https://github.com/apache/spark/pull/5659#discussion_r30263973
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -342,9 +342,37 @@ class Analyzer(
             }
             j.copy(right = newRight)
     
    +      // When resolve `SortOrder`s in Sort based on child, don't report 
errors as
    +      // we still have chance to resolve it based on grandchild
    +      case s @ Sort(ordering, global, child) =>
    +        var changed = false
    +        val newOrdering = ordering.map { order =>
    +          // Resolve SortOrder in one round, or fail and return the origin 
one.
    +          try {
    +            val newOrder = order transformUp {
    +              case u @ UnresolvedAttribute(nameParts) =>
    +                child.resolve(nameParts, resolver).getOrElse(u)
    +              case UnresolvedExtractValue(child, fieldName) if 
child.resolved =>
    +                ExtractValue(child, fieldName, resolver)
    +            }
    +            if (!newOrder.fastEquals(order)) {
    +              changed = true
    +            }
    +            newOrder.asInstanceOf[SortOrder]
    +          } catch {
    +            case a: AnalysisException => order
    +          }
    +        }
    +
    +        if (changed) {
    +          Sort(newOrdering, global, child)
    +        } else {
    +          s
    +        }
    --- End diff --
    
    Two suggestions here:
     - Can we share the code with the block below? and only add a try/catch 
around it?
     - I think we can probably avoid the `changed` optimization.  The rule 
executor and transform already do checks to avoid churn when the plan does not 
change.  Either way, I think its better to keep rules simple even if there is a 
small performance penalty.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to