简体   繁体   English

使用Spark从Hadoop读取JSON文件

[英]Reading JSON files from Hadoop with Spark

I have several JSON files (zipped with .gz format) in some HDFS directories in a tree like: 我在树中的某些HDFS目录中有几个JSON文件(以.gz格式压缩):

/master/dir1/file1.gz
       /dir2/file2.gz
       /dir3/file3.gz
       ...

I need to read those files from the path /master/ and join them into a RDD with Spark in Java. 我需要从路径/ master /中读取这些文件,并使用Java中的Spark将它们加入到RDD中。 How could I do it? 我该怎么办?

[Edit] If [编辑]如果

JavaRDD<String> textFile = sc.textFile("hdfs://master/dir*/file*");

doesn't work, another way is to list the files and union 不起作用,另一种方法是列出文件并合并

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM