将文件加载到猪中并对其进行解压缩 [英] Loading files into pig and decompressing them

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

问题描述

我将一堆来自Azure存储的文件加载到猪身上。
Pig对gzip有默认支持,所以如果文件扩展名为.gz,那么一切正常。



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



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

解决方案

我真的不知道其他一些选项可用,但您可以尝试类似这样的功能。


  1. 写一个bash脚本,将给定的zip文件转换为gz文件

  2. 在pig中加载gz文件

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

  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

mysc ript.pig
A = LOAD'$ PIG_INPUT_FILE'使用PigStorage(',');
DUMP A;

输出:

  $ ./test.sh input.zip 

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

其他可能的选项是您可能需要编写一个UDF将zip转换为gz使用 java.util.zip 库并调用 LoadFunc 选项。我没有尝试这个选项,但如果你想,你可以试试看。

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.

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

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. write a bash script which will convert the given zip file to gz file
  2. load the gz file in pig

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;

Output:

$ ./test.sh input.zip

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

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.

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

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