Sparkr write DF as file csv/txt

我的梦境 提交于 2019-12-01 01:26:36

Spark 2.0+

You can use write.text function:

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)

or write.df with built-in SparkR csv writer:

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

Spark 1.x

You can use spark-csv package:

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

It can be added for example with packages argument to 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

For other options see the official documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!