作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
拜托,我需要这段代码的帮助:
public class ThirdQueryReducer extends
Reducer<IntWritable, Text, NullWritable, Text> {
private NullWritable nullWritableKey = NullWritable.get();
private Text outputValue = new Text();
private StringBuilder buildOutputValue(IntWritable key,
StringBuilder reduceValueBuilder, Text value) {
}
@Override
public void reduce(IntWritable key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
}}
我如何实现 buildOutputValue?知道映射器中的输出是这样的:mapDriver.withOutput(new IntWritable(1981), new Text("Mercurey"));
并且 buildOutputValue() 必须像这样处理日期:
List<Text> values = new ArrayList<Text>();
values.add(new Text("Pommard"));
values.add(new Text("Gentil"));
reduceDriver.withInput(new IntWritable(1980), values);
reducer 中的输出是这样的:
reduceDriver.withOutput(NullWritable.get(), new Text("Pommard\nGentil"));
提前致谢
最佳答案
你可以像下面这样实现它:
公共(public)类 ThirdQueryReducer 扩展 reducer {
private NullWritable nullWritableKey = NullWritable.get();
private Text outputValue = new Text();
private StringBuilder buildOutputValue(IntWritable key,
StringBuilder reduceValueBuilder, Text value) {
return reduceValueBuilder.append(value);
}
@Override
public void reduce(IntWritable key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
Iterator<Text> valueIter = values.iterator();
StringBuilder reduceValueBuilder = new StringBuilder();
while (valueIter.hasNext()) {
buildOutputValue(key, valueIter.next(), reduceValueBuilder);
if (valueIter.hasNext()) {
reduceValueBuilder.append("\n");
}
}
context.write(NullWritable.get(), new Text(reduceValueBuilder.toString()));
}
关于java - 如何构建 buildOutputValue 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41718755/
拜托,我需要这段代码的帮助: public class ThirdQueryReducer extends Reducer { private NullWritable nullWritabl
我是一名优秀的程序员,十分优秀!