zhengruifeng commented on code in PR #53150:
URL: https://github.com/apache/spark/pull/53150#discussion_r2550004092
##########
mllib/src/main/scala/org/apache/spark/ml/util/ReadWrite.scala:
##########
@@ -1142,4 +1144,47 @@ private[spark] object ReadWriteUtils {
spark.read.parquet(path).as[T].collect()
}
}
+
+ def saveDataFrame(path: String, df: DataFrame): Unit = {
+ if (localSavingModeState.get()) {
+ val filePath = Paths.get(path)
+ Files.createDirectories(filePath.getParent)
+
+ Using.resource(
+ new ObjectOutputStream(new BufferedOutputStream(new
FileOutputStream(filePath.toFile)))
+ ) { oos =>
+ val schema: StructType = df.schema
+ oos.writeObject(schema)
+ val it = df.toLocalIterator()
+ while (it.hasNext) {
+ oos.writeBoolean(true) // hasNext = True
+ val row: Row = it.next()
+ oos.writeObject(row)
+ }
+ oos.writeBoolean(false) // hasNext = False
+ }
+ } else {
+ df.write.parquet(path)
+ }
+ }
+
+ def loadDataFrame(path: String, spark: SparkSession): DataFrame = {
+ if (localSavingModeState.get()) {
+ Using.resource(
+ new ObjectInputStream(new BufferedInputStream(new
FileInputStream(path)))
+ ) { ois =>
+ val schema = ois.readObject().asInstanceOf[StructType]
Review Comment:
resort to arrow format suggested by @cloud-fan
--
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]