Java 在Hadoop中将Reducer的输出添加到列表中
我试图将Java 在Hadoop中将Reducer的输出添加到列表中,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,我试图将减速机的输出添加到列表中,然后在读取所有值后访问并打印列表 以下是我正在做的: public class Reducer extends Reducer<Text, BooleanWritable, Text, BooleanWritable> { public static final Logger LOG = LoggerFactory.getLogger(Reducer.class); public List<String> keys= new Ar
减速机的输出添加到列表中,然后在读取所有值后访问并打印列表
以下是我正在做的:
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);
}
}
公共类Reducer扩展Reducer{
公共静态最终记录器LOG=LoggerFactory.getLogger(Reducer.class);
公共列表键=新的ArrayList(1000);
公共void reduce(文本键、Iterable值、上下文上下文)引发IOException、InterruptedException{
for(布尔可写值:值){
key.add(key.toString());
编写(键、值);
}
打印(钥匙);
}
私有无效打印(字符串键){
用于(字符串键:键){
日志信息(密钥);
}
}
但是,它并没有像预期的那样发挥作用。
我只想在将减速器中的所有值添加到您需要使用的列表后打印列表一次,该列表称为每个减速器任务一次。
protectedvoid cleanup(org.apache.hadoop.mapreduce.Reducer.Context)
抛出IOException、InterruptedException
请参阅此项。您需要使用它,它在每个任务中调用一次。
protectedvoid cleanup(org.apache.hadoop.mapreduce.Reducer.Context)
抛出IOException、InterruptedException
参考这个