按字段分组的Reducer

Posted 杨鑫newlfe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了按字段分组的Reducer相关的知识,希望对你有一定的参考价值。

<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>

以上是关于按字段分组的Reducer的主要内容,如果未能解决你的问题,请参考以下文章