[英]Reading JSON files from Hadoop with Spark
我在樹中的某些HDFS目錄中有幾個JSON文件(以.gz格式壓縮):
/master/dir1/file1.gz
/dir2/file2.gz
/dir3/file3.gz
...
我需要從路徑/ master /中讀取這些文件,並使用Java中的Spark將它們加入到RDD中。 我該怎么辦?
[編輯]如果
JavaRDD<String> textFile = sc.textFile("hdfs://master/dir*/file*");
不起作用,另一種方法是列出文件並合並
fileSystem.listStatus(new Path("hdfs://master/dir*"))
.filter(d -> d.isDirectory())
.map(p -> sc.textFile(p.getPath()))
.reduce((a, b) -> a.unionAll(b))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.