Github user zhichao-li commented on a diff in the pull request: https://github.com/apache/spark/pull/10731#discussion_r50072670 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -445,6 +445,26 @@ class Analyzer( val newOrdering = resolveSortOrders(ordering, child, throws = false) Sort(newOrdering, global, child) + // Resolve the order index to be a specific column + case s @ Sort(ordering, global, child) if child.resolved && s.resolved => + def indexToColumn(index: Int, direction: SortDirection) = { + val orderNodes = child.output + if (index > 0 && index <= orderNodes.size) { + SortOrder(orderNodes(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 ${orderNodes.size}""".stripMargin) + } + } + val newOrdering = ordering map { --- End diff -- Seems like it might be more reasonable from the semantic point of view to override the `resolved` method and move the logic to resolveSortOrders.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org