我们已经意识到将GZip格式的文件归档用于Hadoop处理并不是一个好主意.GZip不可拆分,以供参考,以下是我不会重复的问题:
我的问题是:BZip2是最好的归档压缩,它允许Hadoop并行处理单个归档文件吗?Gzip肯定不是,从我的阅读LZO有一些问题.
我有以下问题:假设我有一个包含压缩目录的目录,其中包含存储在HDFS上的多个文件.我想创建一个包含T类型对象的RDD,即:
context = new JavaSparkContext(conf);
JavaPairRDD<String, String> filesRDD = context.wholeTextFiles(inputDataPath);
JavaPairRDD<String, String> filesRDD = context.wholeTextFiles(inputDataPath);
JavaRDD<T> processingFiles = filesRDD.map(fileNameContent -> {
// The name of the file
String fileName = fileNameContent._1();
// The content of the file
String content = fileNameContent._2();
// Class T has a constructor of taking the filename and the content of each
// processed file (as two strings)
T t = new T(content, fileName);
return t;
});
Run Code Online (Sandbox Code Playgroud)
现在什么时候inputDataPath
是一个包含文件的目录,这完全正常,即它是这样的:
String inputDataPath = "hdfs://some_path/*/*/"; // because …
Run Code Online (Sandbox Code Playgroud) 我有zip文件,我想打开'通过'Spark.我可以打开.gzip文件没有问题,因为Hadoops本机编解码器支持,但无法使用.zip文件.
有没有一种简单的方法来读取Spark代码中的zip文件?我还搜索了要添加到CompressionCodecFactory的zip编解码器实现,但到目前为止还没有成功.
我有一个包含多个文本文件的Zipped文件.我想读取每个文件并构建一个包含每个文件内容的RDD列表.
val test = sc.textFile("/Volumes/work/data/kaggle/dato/test/5.zip")
Run Code Online (Sandbox Code Playgroud)
将只是整个文件,但如何遍历zip的每个内容,然后使用Spark将其保存在RDD中.
我对Scala或Python很好.
Python中使用Spark的可能解决方案 -
archive = zipfile.ZipFile(archive_path, 'r')
file_paths = zipfile.ZipFile.namelist(archive)
for file_path in file_paths:
urls = file_path.split("/")
urlId = urls[-1].split('_')[0]
Run Code Online (Sandbox Code Playgroud)