spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-12789] [SQL] Support Order By Ordinal i...
Date Mon, 21 Mar 2016 06:07:12 GMT
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11815#discussion_r56784850
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
    @@ -618,13 +622,36 @@ class Analyzer(
        * clause.  This rule detects such queries and adds the required attributes to the
original
        * projection, so that they will be available during sorting. Another projection is
added to
        * remove these attributes after sorting.
    +   *
    +   * This rule also resolves the position number in sort references. This support is
introduced
    +   * in Spark 2.0. Before Spark 2.0, the integers in Order By has no effect on output
sorting.
    +   * - When the sort references are not integer but foldable expressions, ignore them.
    +   * - When spark.sql.orderByOrdinal is set to false, ignore the position numbers too.
        */
       object ResolveSortReferences extends Rule[LogicalPlan] {
         def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
    +      case s: Sort if !s.child.resolved => s
    +      // 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 conf.orderByOrdinal && 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,
    +                "Order/sort By position: $index does not exist " +
    --- End diff --
    
    seems you miss a `s` at head?  Should be `s"... $index..."`


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