我想用Apache pig把一个文件分成4个相等的部分。例如,如果一个文件有100行,前25行应该转到第一个输出文件,依此类推。最后25行应该转到第四个输出文件。有人能帮我做到这一点吗。我使用Apache Pig,因为文件中的记录数将以百万为单位,并且之前的步骤需要使用pig生成需要拆分的文件。
发布于 2016-04-08 10:30:16
我对此做了一些挖掘,因为它出现在hadoop的Hortonworks示例考试中。它似乎没有很好的文档记录-但它真的很简单。在本例中,我使用了可从dev.mysql.com下载的国家/地区示例数据库:
grunt> storeme = order data by $0 parallel 3;
grunt> store storeme into '/user/hive/countrysplit_parallel';
然后,如果我们看一下hdfs中的目录:
[root@sandbox arthurs_stuff]# hadoop fs -ls /user/hive/countrysplit_parallel
Found 4 items
-rw-r--r-- 3 hive hdfs 0 2016-04-08 10:19 /user/hive/countrysplit_parallel/_SUCCESS
-rw-r--r-- 3 hive hdfs 3984 2016-04-08 10:19 /user/hive/countrysplit_parallel/part-r-00000
-rw-r--r-- 3 hive hdfs 4614 2016-04-08 10:19 /user/hive/countrysplit_parallel/part-r-00001
-rw-r--r-- 3 hive hdfs 4768 2016-04-08 10:19 /user/hive/countrysplit_parallel/part-r-00002
希望这能有所帮助。
发布于 2015-09-24 15:34:20
你可以使用下面的一些猪功能来达到你想要的效果。
自定义清管库拆分函数http://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#SPLIT
您必须根据您的数据提供一些条件。
发布于 2015-09-24 08:00:45
这是可以做到的。但也许还有更好的选择。
A = LOAD 'file' using PigStorage() as (line:chararray);
B = RANK A;
C = FILTER B BY rank_A > 1 and rank_A <= 25;
D = FILTER B BY rank_A > 25 and rank_A <= 50;
E = FILTER B BY rank_A > 50 and rank_A <= 75;
F = FILTER B BY rank_A > 75 and rank_A <= 100;
store C into 'file1';
store D into 'file2';
store E into 'file3';
store F into 'file4';
https://stackoverflow.com/questions/32753421
复制