【发布时间】:2018-09-10 03:13:28
【问题描述】:
我有一个包含顶点 id 和它的 x,y 坐标的 RDD,我想将它的内容写入文本文件,在我的本地机器上我正在使用函数来执行此操作
def printVertices(iterable: Iterable[Vertex], filename: String): Unit = {
val pw = new PrintWriter(new File(filename))
for (point <- iterable) {
pw.write(point.id + ", " + point.coordinate.x + ", " + point.coordinate.y + "\n")
}
pw.close()
}
printVertices(dt.points.collect, s"$output/points$id.txt")
在上面的代码中 dt.points 是一个 RDD,如果我做 RDD.saveAsTextFile 它会写入整个 RDD,我想将它保存到一个文本文件中,所以我想使用我的方法写入 s3。
【问题讨论】:
标签: scala amazon-web-services apache-spark amazon-s3 amazon-emr