我正在尝试将 reducer
的输出添加到 list
中,然后在读取所有值后访问并打印列表。
这是我正在做的:-
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 中的所有值都添加到 list
最佳答案
您需要使用 which 在每个 reducer 任务中调用一次。
protected 无效清理(org.apache.hadoop.mapreduce.Reducer.Context 上下文)
抛出 IOException、InterruptedException
引用这个documentation .
关于java - 将 Reducer 的输出添加到 Hadoop 中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39129688/