HBase与MapReduce整合--附案例

本文详细介绍了如何将HBase与MapReduce进行整合,包括编写Mapper类、Reducer类以及Driver程序。在实施过程中,需要将Hadoop的相关配置文件如core-site.xml、hdfs-site.xml等放入工程src目录,并确保添加了Hadoop的jar到classpath,最后执行程序完成数据处理。
摘要由CSDN通过智能技术生成

1.编写mapper类

public class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
		Text word = new Text();
		IntWritable one = new IntWritable(1);
		/**
		 * map函数:处理行,有几行处理几行。如test1.txt文本中有4行,那么map()调用4次
		 */
		@Override
		protected void map(LongWritable key, Text value,Context context)
				throws IOException, InterruptedException {
			StringTokenizer itr = new StringTokenizer(value.toString());
			while(itr.hasMoreTokens()){
			word.set(itr.nextToken());
			context.write(word,one);
		    } 
		}
	}

2.编写Reducer

 public class MyReduce extends TableReducer<Text, IntWritable, Text> {
		IntWritable result = new IntWritable();	
		protected void reduce(Text k2, Iterable<IntWritable> v2,Context context)
				throws IOException, InterruptedException {
			int sum = 0;
			for (IntWritable value : v2) {
				sum&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值