You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by rxin <gi...@git.apache.org> on 2016/03/17 05:36:15 UTC

[GitHub] spark pull request: [SPARK-12789]Support order by index and group ...

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

    https://github.com/apache/spark/pull/10731#discussion_r56454667
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala ---
    @@ -497,6 +498,41 @@ class Analyzer(
               ordering.map(order => resolveExpression(order, child).asInstanceOf[SortOrder])
             Sort(newOrdering, global, child)
     
    +      // Replace the index with the related attribute for ORDER BY
    +      // which is a 1-base position of the projection list.
    +      case s @ Sort(orders, global, child) if child.resolved &&
    +        orders.exists(o => IntegerIndex.unapply(o.child).nonEmpty) =>
    +        val newOrders = orders map {
    +          case s @ SortOrder(IntegerIndex(index), direction) =>
    +            if (index > 0 && index <= child.output.size) {
    +              SortOrder(child.output(index - 1), direction)
    +            } else {
    +              throw new UnresolvedException(s,
    +                s"""Order by position: $index does not exist \n
    +                    |The Select List is indexed from 1 to ${child.output.size}""".stripMargin)
    +            }
    +          case other => other
    +        }
    +        Sort(newOrders, global, child)
    +
    +      // Replace the index with the related attribute for Group BY
    +      // which is a 1-base position of the underlying columns.
    +      case a @ Aggregate(groups, aggs, child) if child.resolved &&
    +        groups.exists(IntegerIndex.unapply(_).nonEmpty) =>
    +        val newGroups = groups map {
    +          case IntegerIndex(index) =>
    +            val attributes = child.output
    --- End diff --
    
    I'm not sure if this is correct. 1 and 2 in the group by here refers to the position 1 and 2 in the select list, not the underlying query output.


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