Sparkr将DF作为csv/txt文件写入 [英] Sparkr write DF as file csv/txt

查看:945
本文介绍了Sparkr将DF作为csv/txt文件写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用纱线模式研究sparkR.

Hi I'm working on sparkR in yarn mode.

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

I need to write a sparkr df to a csv/txt file.

我看到有write.df,但是它写了实木复合地板文件.

I saw that there is write.df but it writes parquet files.

我试图做这件事

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

但是我在contextCleaner上收到了很多警告和一些错误.

But I got many WARN and some ERROR on contextCleaner.

有什么办法吗?

推荐答案

Spark 2.0 +

您可以使用write.text功能:

将SparkDataFrame的内容保存在文本文件中,该文本文件位于 指定的路径. SparkDataFrame必须仅包含一列 名称为值"的字符串类型.每行变成一个新行 输出文件.

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)

带有内置SparkR csv编写器的

write.df:

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

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

火花1.x

您可以使用 spark-csv 软件包:

You can use spark-csv package:

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

例如可以使用SparkR/spark-submitpackages参数添加它:

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

这篇关于Sparkr将DF作为csv/txt文件写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆