我已经稍微修改了 spark 的示例,以便通过 hdfs 在 ec2 集群上工作。但是我只得到了保存到镶木地板文件的示例。
library(SparkR)
# Initialize SparkContext and SQLContext
sc <- sparkR.init()
sqlContext <- sparkRSQL.init(sc)
# Create a simple local data.frame
localDF <- data.frame(name=c("John", "Smith", "Sarah"), age=c(19, 23, 18))
# Create a DataFrame from a JSON file
peopleDF <- jsonFile(sqlContext, file.path("/people.json"))
# Register this DataFrame as a table.
registerTempTable(peopleDF, "people")
# SQL statements can be run by using the sql methods provided by sqlContext
teenagers <- sql(sqlContext, "SELECT name FROM people WHERE age >= 13 AND age <= 19")
# Store the teenagers in a table
saveAsParquetFile(teenagers, file.path("/teenagers"))
# Stop the SparkContext now
sparkR.stop()
当我使用saveDF
代替时saveAsParquetFile
,我只会在 hdfs 中得到一个空文件。
drwxr-xr-x - root supergroup 0 2015-07-23 15:14 /teenagers
如何将我的数据框存储为文本文件(json/csv/...)?