zhengruifeng commented on code in PR #47328:
URL: https://github.com/apache/spark/pull/47328#discussion_r1676692203


##########
mllib/src/main/scala/org/apache/spark/ml/r/AFTSurvivalRegressionWrapper.scala:
##########
@@ -129,7 +129,9 @@ private[r] object AFTSurvivalRegressionWrapper extends 
MLReadable[AFTSurvivalReg
       val rMetadata = ("class" -> instance.getClass.getName) ~
         ("features" -> instance.features.toImmutableArraySeq)
       val rMetadataJson: String = compact(render(rMetadata))
-      sc.parallelize(Seq(rMetadataJson), 1).saveAsTextFile(rMetadataPath)
+      sparkSession.createDataFrame(
+        Seq(Tuple1(rMetadataJson))
+      ).repartition(1).write.text(rMetadataPath)

Review Comment:
   No, the single partition is needed to avoid creating empty files, even 
though there is only one row:
   
   ```
   spark.range(1).select(sf.lit("123")).write.text("/tmp/test-test")
   ```
   
   ```
   (base) ➜  runtime git:(master) ls /tmp/test-test
   _SUCCESS                                                 
part-00011-e548682e-21a5-41ea-93bc-0089efccbf4f-c000.txt
   part-00000-e548682e-21a5-41ea-93bc-0089efccbf4f-c000.txt
   (base) ➜  runtime git:(master) wc -l /tmp/test-test/*
          0 /tmp/test-test/_SUCCESS
          0 
/tmp/test-test/part-00000-e548682e-21a5-41ea-93bc-0089efccbf4f-c000.txt
          1 
/tmp/test-test/part-00011-e548682e-21a5-41ea-93bc-0089efccbf4f-c000.txt
          1 total
   ```
   
   But I think we can use `coalesce(1)` to avoid this small shuffle



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to