spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hvanhovell <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-12063][SQL] Use number in group by clau...
Date Fri, 18 Dec 2015 16:58:12 GMT
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10052#discussion_r48045669
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
    @@ -178,6 +179,46 @@ class Analyzer(
         }
       }
     
    +  /**
    +   * Replaces queries of the form "SELECT expr FROM A GROUP BY 1 ORDER BY 1"
    +   * with a query of the form "SELECT expr FROM A GROUP BY expr ORDER BY expr"
    +   */
    +  object ResolveNumericReferences extends Rule[LogicalPlan] {
    +
    +    def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
    +      case Aggregate(groups, aggs, child) =>
    +        val newGroups = groups.map {
    +          case group if group.isInstanceOf[Literal] && group.dataType.isInstanceOf[IntegralType]
=>
    +            aggs(group.toString.toInt - 1) match {
    +              case u: UnresolvedAlias =>
    +                u.child match {
    +                  case UnresolvedStar(_) => // Can't replace literal with column yet
    +                    group
    +                  case _ => u.child
    +                }
    +              case a: Alias => a.child
    +              case a: AttributeReference => a
    +            }
    +          case group => group
    +        }
    +        Aggregate(newGroups, aggs, child)
    +      case Sort(ordering, global, child) =>
    +        val newOrdering = ordering.map {
    +          case o if o.child.isInstanceOf[Literal] && o.dataType.isInstanceOf[IntegralType]
=>
    --- End diff --
    
    Same comment as above.


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