Spark 支持 gzip 格式吗? [英] Is gzip format supported in Spark?

查看:32
本文介绍了Spark 支持 gzip 格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于大数据项目,我打算使用 spark,它具有一些不错的功能,例如用于重复工作负载的内存计算.它可以在本地文件或 HDFS 之上运行.

For a Big Data project, I'm planning to use spark, which has some nice features like in-memory-computations for repeated workloads. It can run on local files or on top of HDFS.

但是,在官方文档中,我找不到有关如何处理 gzip 文件的任何提示.在实践中,处理 .gz 文件而不是解压文件会非常有效.

However, in the official documentation, I can't find any hint as to how to process gzipped files. In practice, it can be quite efficient to process .gz files instead of unzipped files.

有没有办法手动实现读取 gzipped 文件,或者在读取 .gz 文件时是否已经自动解压?

Is there a way to manually implement reading of gzipped files or is unzipping already automatically done when reading a .gz file?

推荐答案

来自 Spark Scala 编程指南的 关于Hadoop 数据集"的部分:

From the Spark Scala Programming guide's section on "Hadoop Datasets":

Spark 可以从存储在 Hadoop 分布式文件系统 (HDFS) 或 Hadoop 支持的其他存储系统(包括您的本地文件系统、Amazon S3、Hypertable、HBase 等)中的任何文件创建分布式数据集.Spark 支持文本文件、SequenceFile 和任何其他 Hadoop InputFormat.

Spark can create distributed datasets from any file stored in the Hadoop distributed file system (HDFS) or other storage systems supported by Hadoop (including your local file system, Amazon S3, Hypertable, HBase, etc). Spark supports text files, SequenceFiles, and any other Hadoop InputFormat.

对 gzip 输入文件的支持应该与它在 Hadoop 中的工作方式相同.例如,sc.textFile("myFile.gz") 应该自动解压并读取 gzip 压缩的文件(textFile() 实际上是 使用 Hadoop 的 TextInputFormat 实现code>,支持 gzip 压缩文件).

Support for gzip input files should work the same as it does in Hadoop. For example, sc.textFile("myFile.gz") should automatically decompress and read gzip-compressed files (textFile() is actually implemented using Hadoop's TextInputFormat, which supports gzip-compressed files).

正如@nick-chammas 在评论中提到的:

As mentioned by @nick-chammas in the comments:

请注意,如果您在 gzip 压缩文件上调用 sc.textFile(),Spark 将给出你是一个只有 1 个分区的 RDD(从 0.9.0 开始).这是因为gzipped 文件是 不可拆分.如果你不重新分区 RDD不知何故,对该 RDD 的任何操作都将仅限于单个核心

note that if you call sc.textFile() on a gzipped file, Spark will give you an RDD with only 1 partition (as of 0.9.0). This is because gzipped files are not splittable. If you don't repartition the RDD somehow, any operations on that RDD will be limited to a single core

这篇关于Spark 支持 gzip 格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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