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