felipepessoto commented on code in PR #13726:
URL: https://github.com/apache/gluten/pull/13726#discussion_r4686517747


##########
backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala:
##########
@@ -256,37 +256,33 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
       if (projectList.nonEmpty) ProjectExecTransformer(projectList, plan) else 
plan
 
     writeAndCommit(job, description, committer) {
-      val (planToExecute, concurrentOutputWriterSpec) = if (orderingMatched) {
-        (empty2NullPlan, None)
+      def collapseStages(input: SparkPlan): SparkPlan =
+        GenerateTransformStageId()(
+          ColumnarCollapseTransformStages(new 
GlutenConfig(sparkSession.sessionState.conf))(input))
+      // Spark's concurrent output writers read the partition values of every 
row, which a
+      // BatchCarrierRow doesn't expose, so always sort by partition, as when
+      // spark.sql.maxConcurrentOutputFileWriters is 0.
+      val planToExecute = if (orderingMatched) {
+        // The empty-to-null project is a bare transformer, which can't run 
outside a stage.
+        if (projectList.nonEmpty) collapseStages(empty2NullPlan) else 
empty2NullPlan

Review Comment:
   `orderingMatched` describes the input before `Empty2Null`. For 
`partitionBy("s", "p")`, `(null, 1), (null, 2), ("", 1), ("", 2)` is sorted, 
but the projection turns the partition keys into `(null, 1), (null, 2), (null, 
1), (null, 2)`. If those runs cross batch boundaries, the single writer closes 
and reopens each partition, creating extra files even with one task and no 
file-size limit. The Delta 4 branch has the same issue. Can we skip the writer 
sort only when the projected keys stay grouped? A one-task, small-batch test 
that checks the committed file count per partition would catch this; the rows 
still read back correctly.



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