Github user adrian-wang commented on a diff in the pull request: https://github.com/apache/spark/pull/5208#discussion_r28302133 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/Exchange.scala --- @@ -69,7 +72,16 @@ case class Exchange(newPartitioning: Partitioning, child: SparkPlan) extends Una } } val part = new HashPartitioner(numPartitions) - val shuffled = new ShuffledRDD[Row, Row, Row](rdd, part) + val shuffled = sort match { + case false => new ShuffledRDD[Row, Row, Row](rdd, part) + case true => + val sortingExpressions = expressions.zipWithIndex.map { + case (exp, index) => + new SortOrder(BoundReference(index, exp.dataType, exp.nullable), Ascending) --- End diff -- I don't quite understand. If not using BoundReference here, we are likely to run into ArrayIndexOutOfBound if some columns get pruned or column order changed during optimization.
--- 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