Sparkr 将 DF 写入文件 csv/txt

Sparkr write DF as file csv/txt

嗨,我正在 yarn 模式下开发 sparkR。

我需要将 sparkr df 写入 csv/txt 文件。

我看到有 write.df 但它写入镶木地板文件。

我试过做这件事

RdataFrame<-collect(SparkRDF)
write.table(RdataFrame, ..)

但是我在 contextCleaner 上收到了很多 WARN 和一些 ERROR。

有什么办法吗?

Spark 2.0+

您可以使用write.text函数:

Save the content of the SparkDataFrame in a text file at the specified path. The SparkDataFrame must have only one column of string type with the name "value". Each row becomes a new line in the output file.

write.text(df, path)

write.df 与 built-in SparkR csv 作者:

write.df(df, path, source="csv")

火花1.x

您可以使用 spark-csv 包:

write.df(SparkRDF, "foo.csv", "com.databricks.spark.csv", ...)

它可以用 packages 参数添加到 SparkR / spark-submit:

sparkR --packages com.databricks:spark-csv_2.10:1.3.0 # For Scala 2.10
sparkR --packages com.databricks:spark-csv_2.11:1.3.0 # For Scala 2.11

有关其他选项,请参阅 the official documentation