从 sparkR 作业导出数据

Exporting data from a sparkR job

我有一个类似于示例的 R 脚本,您可以在其中加载一些 来自 hdfs 的数据,然后以某种方式存储它,在本例中是通过 Parquet 文件。

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()

如何将集群中的数据检索到另一个 spark 中 应用?我目前正在考虑连接到 hdfs master 并根据 this 检索文件 例子, 除了将 sbt-thrift 替换为 scrooge.

是否有更惯用的方式来检索数据而无需直接 连接到hadoop集群?我考虑过将数据复制出来 hdfs,但 parquet 只能从我的 hadoop 中读取 明白了。

使用主 local 启动 SparkContext 并使用 SparkSQL 检索数据。