org.apache.hadoop.hbase.coprocessor.AggregateImplementation 来统计表的行数

hbase自带了一个聚合coprocessor类:org.apache.hadoop.hbase.coprocessor.AggregateImplementation。使用该类可以count一张表的总记录数。

当然在hbase shell下面也可以count <table_name>来统计。我这里比较了一下两者的执行时间,我有一张表有700多万的数据,在hbase shell下count足足花费了我12分钟的时间,而用coprocessor来统计,只花费了78秒!!!由此可见coprocessor的强大。



hbase aip 添加协处理器:

              Configuration hbaseconfig = HBaseConfiguration.create();

              HBaseAdmin hbaseAdmin = new HBaseAdmin(hbaseconfig);
              hbaseAdmin.disableTable(TABLE_NAME);

              HTableDescriptor htd = hbaseAdmin.getTableDescriptor(TABLE_NAME);
              htd.addCoprocessor(AggregateImplementation.class.getName());
              hbaseAdmin.modifyTable(TABLE_NAME, htd);
              hbaseAdmin.enableTable(TABLE_NAME);
              hbaseAdmin.close();

使用hbase提供的聚合coprocessor:

 AggregationClient aggregationClient = new AggregationClient(hbaseconfig);
                Scan scan = new Scan();
                scan.addFamily(Bytes.toBytes("fr"));
                Date start = new Date();
                long rowcount = aggregationClient.rowCount(TABLE_NAME,
                                new LongColumnInterpreter(), scan);
                Date end = new Date();
                System.out.println("rowcount:" + rowcount);
                System.out.println("timecost:" + (end.getTime() - start.getTime()));

hbase shell添加coprocessor:

disable 'member'
alter 'member',METHOD => 'table_att','coprocessor' => 'hdfs://master24:9000/user/hadoop/jars/test.jar|mycoprocessor.SampleCoprocessor|1001|'
enable 'member'


hbase shell 删除coprocessor:

disable 'member'
alter 'member',METHOD => 'table_att_unset',NAME =>'coprocessor$1'
enable 'member'

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值