2013-04-11 46 views
5
Mapper/Reducer 1 --> (key,value) 
        / | \ 
        / | \ 
    Mapper/Reducer 2  | Mapper/Reducer 4 
    -> (oKey,oValue)  | -> (xKey, xValue) 
          | 
          | 
        Mapper/Reducer 3 
        -> (aKey, aValue) 

我有一个日志文件,我与MR1聚合。 Mapper2,Mapper3,Mapper4将MR1的输出作为输入。工作是链接的。Hadoop - 如何使用和减少多个输入?

MR1输出:

User  {infos of user:[{data here},{more data},{etc}]} 
.. 

MR2输出:

timestamp  idCount 
.. 

MR3输出:

timestamp  loginCount 
.. 

MR4输出:

timestamp  someCount 
.. 

我想输出从MR2-4结合:最终输出 - >

timestamp  idCount  loginCount someCount 
.. 
.. 
.. 

是有办法的w/o猪或蜂巢?我正在使用Java。

+1

单独为ASCII艺术+1。 – 2013-04-11 11:58:50

+0

第二步是不可能有一个多功能的MR作业,看到你的关键是所有的时间戳?即解释已经传入的值并相应地处理它?看到reducer保证接收给定密钥的所有值,您可以收集与时间戳相关的所有信息,并只在您拥有所需的所有组件时才写出。 – Quetzalcoatl 2013-04-11 12:01:56

+0

其实我这样做,它的工作。弹出一个问题:为了实现我想要的功能,我在映射函数中向context(context.write(key1,value1))写了3次 - 在代码context.write(key2,value2)和结尾上下文中更深入。写(key3,value3)。这是可行的吗? – JustTheAverageGirl 2013-04-11 13:12:43

回答

1

据我所知,你不能在减速器类输出的阵列。 什么我脑海解决你的问题如下:

您的MR1输出关键是{a,b,c}之一是其中根据键{timestamp,idCount}{timestamp, loginCount}{timestamp, someCount}对。你会结合MR2-4

所以过程将是这样的:

MR1 <inputKey,inputValue,outputKey,outPutValue> where outputKey is 
             "a" for outValue`{timestamp,idCount} 
             "b" for outValue`{timestamp, loginCount} 
             "c" for outValue`{timestamp, someCount} 

MR2-4<inputKey,inputValue,outputKey,outPutValue> if inputkey is "a" do MR2 
               if inputkey is "b" do MR3 
               if inputkey is "c" do MR4 

另外,还有一些方法称为Partitioner and GroupComperator中,你可以使用{键/值}和映射器/减速器发挥可以考虑key+some_part_of_value关键。