<strong><span style="font-size:18px;">/*** * @author YangXin * @info 按字段分组的Reducer */ package unitTwelve; import java.io.IOException; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; public class ByKeyReducer extends Reducer<Text, Text, Text, Text> { protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException{ StringBuilder output = new StringBuilder(); for(Text value : values){ output.append(value.toString()).append(" "); } context.write(key, new Text(output.toString().trim())); } } </span></strong>
时间: 2024-12-30 03:31:25