从sparkR作业导出数据

时间:2015-07-24 16:27:28

标签: apache-spark sparkr

我有一个类似于示例的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()

我究竟如何从群集中检索数据到另一个火花 应用?我正在考虑连接到hdfs master 并根据this example检索文件, 除了用s替换sbt-thrift scrooge

有没有更直接的方法来检索数据 连接到hadoop集群?我考虑过复制数据 hdfs,但实木复合地板只能从我所拥有的hadoop中读取 理解。

1 个答案:

答案 0 :(得分:0)

使用主人SparkContext开始local并使用SparkSQL检索数据。

相关问题