hadoop MR从hbase中读取数据写入到hbase中


hadoop MR从hbase中读取数据写入到hbase中的配置

public class WordCount {

    private static final Logger LOGGER= LoggerFactory.getLogger(WordCount.class);

    static class HbaseMapper extends TableMapper<ImmutableBytesWritable,Put>{

        @Override
        protected void map(ImmutableBytesWritable row, Result result, Context context) throws IOException, InterruptedException {

            byte[] b = row.get();
            String keys = Bytes.toString(b);
            byte[] value=result.getValue(Bytes.toBytes(Constants.COLUMN_FAMILY),Bytes.toBytes("f1"));

            LOGGER.info("------keys---::::"+keys);
            LOGGER.info("------values---::::"+Bytes.toString(value));

            context.write(row, resultToPut(row,result));

        }

        private static Put resultToPut(ImmutableBytesWritable key, Result result) throws IOException {
            Put put = new Put(key.get());
            for (KeyValue kv : result.raw()) {
                put.add(kv);
            }
            return put;
        }
    }





    public static void main(String[] args) throws Exception
    {
        Configuration config = HBaseConfiguration.create();
        Job job = Job.getInstance(config,"mytest");
        job.setJarByClass(WordCount.class);     // class that contains mapper

        Scan scan = new Scan();

        //rpc请求的记录数
        scan.setCaching(500);        // 1 is the default in Scan, which will be bad for MapReduce jobs
        scan.setCacheBlocks(false);  // don't set to true for MR jobs

        TableMapReduceUtil.initTableMapperJob(
                Constants.TableName.TEST,        // input HBase table name
                scan,             // Scan instance to control CF and attribute selection
                HbaseMapper.class,   // mapper
                null,             // mapper output key
                null,             // mapper output value
                job);

        TableMapReduceUtil.initTableReducerJob(
                Constants.TableName.RECEIVE,      // output table
                null,             // reducer class
                job);
        job.setNumReduceTasks(0);


        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

hadoop MR从hbase中读取数据写入到hbase中的配置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值