猪 - 排序 - 不同的减速器?

时间:2014-07-30 19:47:32

标签: hadoop mapreduce apache-pig

我是猪的新手。我正在尝试合并加入。满足以下要求:

  

必须在连接键上按升序(ASC)顺序对数据进行排序   侧上。

示例文件:

4, The Object of Beauty, 1991,2.8,6150 
1, The Nightmare Before Christmas, 1993,3.9,4568 
2, The Mummy, 1932,3.5,4388 
3, Orphans of the Storm, 1921,3.2,9062 
3, Orphans of the Storm, 1921,3.2,9062
4, The Object of Beauty, 1991,2.8,6150 
5, Night Tide, 1963,2.8,5126 
6, One Magic Christmas, 1985,3.8,5333 
7, Muriel's Wedding, 1994,3.5,6323 
8, Mother's Boys, 1994,3.4,5733 
9, Nosferatu: Original Version, 1929,3.5,5651 
10, Nick of Time, 1995,3.4,5333 

我在PIG中执行了以下命令:

movies = LOAD 'Sample.csv' using PigStorage (',') as (id: int, name, year, rating, duration); 
movies_sorted movies = order by id ASC PARALLEL 3; 
movies_sorted store into 'output_movies';

执行时:

  

hadoop fs-cat ./output2/part-r-00000

我看到,在不同的分区中有相同键的记录。例如,我在两个不同的分区中拥有id为3的记录。据我所知,具有相同密钥的记录应始终位于同一分区中。 ˚F

可能出现什么问题?

1 个答案:

答案 0 :(得分:3)

在少数情况下,包括ORDER BY和倾斜JOIN,Pig会破坏map-reduce惯例,即将给定键的所有记录发送到一个reducer。 (请注意,排序的概念已经超出了map-reduce范例。)但是,您仍然可以保证,如果按顺序遍历reducers的输出(由part-r-NNNNN中的数字表示),记录将按照规定进行订购。

您可以在this thread中阅读更多内容。