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

    https://github.com/apache/spark/pull/6816#discussion_r32390571
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -397,19 +398,31 @@ class Analyzer(
             }
           case s @ Sort(ordering, global, a @ Aggregate(grouping, aggs, child))
               if !s.resolved && a.resolved =>
    -        val unresolved = ordering.flatMap(_.collect { case 
UnresolvedAttribute(name) => name })
             // A small hack to create an object that will allow us to resolve 
any references that
             // refer to named expressions that are present in the grouping 
expressions.
             val groupingRelation = LocalRelation(
               grouping.collect { case ne: NamedExpression => ne.toAttribute }
             )
     
    -        val (resolvedOrdering, missing) = resolveAndFindMissing(ordering, 
a, groupingRelation)
    +        // Find sort attributes that are projected away so we can 
temporarily add them back in.
    +        val (resolvedOrdering, unresolved) = 
resolveAndFindMissing(ordering, a, groupingRelation)
    +
    +        // Find aggregate expressions and evaluate them early, since they 
can't be evaluated in a
    +        // Sort.
    +        val (withAggsRemoved, aliasedAggregateList) = resolvedOrdering.map 
{
    +          case aggOrdering if aggOrdering.collect { case a: 
AggregateExpression => a }.nonEmpty =>
    +            val aliased = Alias(aggOrdering.child, "_aggOrdering")()
    --- End diff --
    
    They will be, but that does not matter. The names are only for readability.
    All work in execution is done by expression id.
    On Jun 14, 2015 6:24 PM, "Yadong Qi" <[email protected]> wrote:
    
    > In
    > 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
    > <https://github.com/apache/spark/pull/6816#discussion_r32387465>:
    >
    > >          // A small hack to create an object that will allow us to 
resolve any references that
    > >          // refer to named expressions that are present in the grouping 
expressions.
    > >          val groupingRelation = LocalRelation(
    > >            grouping.collect { case ne: NamedExpression => 
ne.toAttribute }
    > >          )
    > >
    > > -        val (resolvedOrdering, missing) = 
resolveAndFindMissing(ordering, a, groupingRelation)
    > > +        // Find sort attributes that are projected away so we can 
temporarily add them back in.
    > > +        val (resolvedOrdering, unresolved) = 
resolveAndFindMissing(ordering, a, groupingRelation)
    > > +
    > > +        // Find aggregate expressions and evaluate them early, since 
they can't be evaluated in a
    > > +        // Sort.
    > > +        val (withAggsRemoved, aliasedAggregateList) = 
resolvedOrdering.map {
    > > +          case aggOrdering if aggOrdering.collect { case a: 
AggregateExpression => a }.nonEmpty =>
    > > +            val aliased = Alias(aggOrdering.child, "_aggOrdering")()
    >
    > If there are more than one aggregation in order by, will it be the same
    > alias name _aggOrdering?
    >
    > —
    > Reply to this email directly or view it on GitHub
    > <https://github.com/apache/spark/pull/6816/files#r32387465>.
    >



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