pan3793 commented on code in PR #52584:
URL: https://github.com/apache/spark/pull/52584#discussion_r2426132718


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala:
##########
@@ -157,6 +153,23 @@ object FileFormatWriter extends Logging {
     val actualOrdering = writeFilesOpt.map(_.child)
       .getOrElse(materializeAdaptiveSparkPlan(plan))
       .outputOrdering
+
+    val requiredOrdering = {
+      // We should first sort by dynamic partition columns, then bucket id, 
and finally sorting
+      // columns.
+      val sortCols = partitionColumns.drop(numStaticPartitionCols) ++
+        writerBucketSpec.map(_.bucketIdExpression) ++ sortColumns
+      val ordering = sortCols.map(SortOrder(_, Ascending))
+      plan.logicalLink match {
+        case Some(WriteFiles(query, _, _, _, _, _)) =>
+          V1WritesUtils.eliminateFoldableOrdering(ordering, 
query).outputOrdering
+        case Some(query) =>
+          V1WritesUtils.eliminateFoldableOrdering(ordering, 
query).outputOrdering
+        case _ =>
+          ordering

Review Comment:
   oh, that makes sense, let me change it back



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to