火花如何下载S3多个gzip文件作为单个RDD? [英] Spark- How to download multiple gzipped files from S3 as a single RDD?

查看:218
本文介绍了火花如何下载S3多个gzip文件作为单个RDD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储在S3很多gzip压缩文件,这些文件按项目和每天每小时组织,文件的路径的模式是:

I have many gzipped files stored on S3 which are organized by project and hour per day, the pattern of the paths of the files is as:

s3://<bucket>/project1/20141201/logtype1/logtype1.0000.gz
s3://<bucket>/project1/20141201/logtype1/logtype1.0100.gz
....
s3://<bucket>/project1/20141201/logtype1/logtype1.2300.gz

由于数据应在每天的基础上进行分析,我必须下载并DECOM preSS文件属于特定的一天,然后组装的内容作为一个单独的RDD。

Since the data should be analyzed on a daily basis, I have to download and decompress the files belongs to a specific day, then assemble the content as a single RDD.

应该有几种方法可以做到这一点,但我想知道星火最佳实践。

There should be several ways can do this, but I would like to know the best practice for Spark.

先谢谢了。

推荐答案

这星火用来访问S3允许您使用的水珠前pression

The underlying Hadoop API that Spark uses to access S3 allows you specify input files using a glob expression.

星火文档:

所有的星火基于文件的输入法,包括文本文件,支持目录运行,COM pressed文件和通配符也是如此。例如,你可以使用文本文件(/我的/目录)文本文件(/我/目录/ *。TXT)文本文件(/我/目录/ *。GZ)

All of Spark’s file-based input methods, including textFile, support running on directories, compressed files, and wildcards as well. For example, you can use textFile("/my/directory"), textFile("/my/directory/*.txt"), and textFile("/my/directory/*.gz").

所以你的情况,你应该能够打开所有这些文件作为一个单独的RDD使用是这样的:

So in your case you should be able to open all those files as a single RDD using something like this:

rdd = sc.textFile("s3://bucket/project1/20141201/logtype1/logtype1.*.gz")

为了记录,你还可以指定用逗号分隔的列表文件,你甚至可以混合使用,与 * 通配符。

例如:

rdd = sc.textFile("s3://bucket/201412??/*/*.gz,s3://bucket/random-file.txt")

简单地说,这样做是:

Briefly, what this does is:


  • * 所有字符串匹配,所以在这种情况下,<$ C $所有文件夹中的所有 GZ 文件C> 201412 ?? 将被载入。

  • 匹配单个字符,因此 201412 ?? 将覆盖所有天2014年12月如 20141201 20141202 ,等等。

  • 让您只需一次加载单独的文件到同一RDD,如随机file.txt的在这种情况下。

  • The * matches all strings, so in this case all gz files in all folders under 201412?? will be loaded.
  • The ? matches a single character, so 201412?? will cover all days in December 2014 like 20141201, 20141202, and so forth.
  • The , lets you just load separate files at once into the same RDD, like the random-file.txt in this case.

这篇关于火花如何下载S3多个gzip文件作为单个RDD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆