将文件加载到 pig 并解压 [英] Loading files into pig and decompressing them

查看:32
本文介绍了将文件加载到 pig 并解压的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Azure 存储中的一堆文件加载到 pig 中.Pig 默认支持 gzip,因此如果文件扩展名为 .gz,一切正常.

I am loading a bunch of files from Azure storage into pig. Pig has default support for gzip so if the file extensions are .gz everything works fine.

问题是旧文件以 .zip 扩展名存储(我有数百万个).

Problem is that older files are stored with .zip extension (I have millions of those).

有没有办法告诉 pig 加载文件并将 .zip 视为 gzip?

Is there a way to tell pig to load files and treat .zip as gzip?

推荐答案

我真的不知道还有其他一些选择,但你可以尝试这样的事情

I really don't know some other options are available but you can try something like this

  1. 编写一个 bash 脚本,将给定的 zip 文件转换为 gz 文件
  2. 在 pig 中加载 gz 文件

只是一个文件的示例,您可能需要根据需要更改脚本.

Just a sample example for one file, you may need to change the script according to your need.

input.zip
1,john
2,cena
3,rock
4,sam

test.sh
#!/bin/bash
FILE_NAME=$(echo $1 | cut -d '.' -f1)
unzip  "$1"
tar czf "$FILE_NAME.gz" "$FILE_NAME"
pig -x local -param PIG_INPUT_FILE="$FILE_NAME.gz" -f myscript.pig

myscript.pig
A = LOAD '$PIG_INPUT_FILE' USING PigStorage(',');
DUMP A;

输出:

$ ./test.sh input.zip

(1,john)
(2,cena)
(3,rock)
(4,sam)

另一个可能的选择是您可能需要编写一个 UDF 来使用 java.util.zip 库将 zip 转换为 gz 并调用 LoadFunc 选项.我没有尝试这个选项,但如果你愿意,你可以尝试一下.

The other possible option is you may need to write a UDF to convert zip to gz using java.util.zip library and call LoadFunc option. I didn't try this option but if you want you can give a try.

这篇关于将文件加载到 pig 并解压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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