2016-08-24 44 views
0

我试图将reducer的输出添加到list中,然后在读取所有值后访问并打印列表。将Reducer的输出添加到Hadoop中的列表中

下面是我在做什么: -

public class Reducer extends Reducer<Text, BooleanWritable, Text, BooleanWritable> { 
    public static final Logger LOG = LoggerFactory.getLogger(Reducer.class); 
    public List<String> keys= new ArrayList<>(1000); 

    public void reduce(Text key, Iterable<BooleanWritable> values, Context context) throws IOException, InterruptedException { 
    for (BooleanWritable value : values) { 
     keys.add(key.toString()); 
     context.write(key, value); 
    } 
    print(keys); 
    } 

    private void print(String keys) { 
    for (String key : keys) { 
     LOG.info(key); 
    } 
} 

但是,按预期的方式是行不通的。 我想在减速器的所有值都添加到list

回答

2

之后,只打印一次列表您需要使用哪个减速器任务调用一次。 protected void cleanup(org.apache.hadoop.mapreduce.Reducer.Context context) throws IOException,InterruptedException

请参考documentation