0

我有一个与示例类似的 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 并根据这个 example检索文件,除了用 scrooge替换 sbt-thrift替换 sbt-thrift 。

有没有更惯用的方法来检索数据而无需直接连接到 hadoop 集群?我考虑将数据从 hdfs 中复制出来,但是 parquet 只能从我所理解的 hadoop 中读取。

4

1 回答 1

0

SparkContext用 master启动一个local并使用SparkSQL来检索数据。

于 2015-08-18T10:52:42.793 回答