diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/EliminateSortsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/EliminateSortsSuite.scala index d7eb048ba8705..e2b599a7c090c 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/EliminateSortsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/EliminateSortsSuite.scala @@ -284,6 +284,15 @@ class EliminateSortsSuite extends PlanTest { comparePlans(optimized, correctAnswer) } + test("SPARK-32318: should not remove orderBy in distribute statement") { + val projectPlan = testRelation.select('a, 'b) + val orderByPlan = projectPlan.orderBy('b.desc) + val distributedPlan = orderByPlan.distribute('a)(1) + val optimized = Optimize.execute(distributedPlan.analyze) + val correctAnswer = distributedPlan.analyze + comparePlans(optimized, correctAnswer) + } + test("should not remove orderBy in left join clause if there is an outer limit") { val projectPlan = testRelation.select('a, 'b) val orderByPlan = projectPlan.orderBy('a.asc, 'b.desc)