zoukankan      html  css  js  c++  java
  • HBase 协处理器统计行数

    环境:cdh5.1.0


    启用协处理器方法1.

    启用协处理器 Aggregation(Enable Coprocessor Aggregation)
    我们有两个方法:1.启动全局aggregation,能过操纵所有的表上的数据。通过修改hbase-site.xml这个文件来实现,只需要添加如下代码:

    <property>
       <name>hbase.coprocessor.user.region.classes</name>
       <value>org.apache.hadoop.hbase.coprocessor.AggregateImplementation</value>
     </property>

    启用协处理器方法2.

    启用表aggregation,只对特定的表生效。通过HBase Shell 来实现。


    (1)disable指定表。hbase> disable 'mytable'


    (2)添加aggregation hbase> alter 'mytable', METHOD => 'table_att','coprocessor'=>'|org.apache.hadoop.hbase.coprocessor.AggregateImplementation||'


    (3)重启指定表 hbase> enable 'mytable'


    代码:

    package com.jamesfen.hbase;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.Scan;
    import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
    import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter;
    import org.apache.hadoop.hbase.coprocessor.ColumnInterpreter;
    import org.apache.hadoop.hbase.util.Bytes;
    
    public class MyAggregationClient {
    
    	private static final byte[] TABLE_NAME = Bytes.toBytes("bigtable1w");
    	private static final byte[] CF = Bytes.toBytes("bd");
    	public static void main(String[] args) throws Throwable {
    	Configuration customConf = new Configuration();
    	customConf.set("hbase.zookeeper.quorum",
    	"192.168.58.101");
    	//提高RPC通信时长
    	customConf.setLong("hbase.rpc.timeout", 600000);
    	//设置Scan缓存
    	customConf.setLong("hbase.client.scanner.caching", 1000);
    	Configuration configuration = HBaseConfiguration.create(customConf);
    	AggregationClient aggregationClient = new AggregationClient(
    	configuration);
    	Scan scan = new Scan();
    	//指定扫描列族,唯一值
    	scan.addFamily(CF);
    	//long rowCount = aggregationClient.rowCount(TABLE_NAME, null, scan);
    	long rowCount = aggregationClient.rowCount(TableName.valueOf("bigtable1w"), new LongColumnInterpreter(), scan);
    	System.out.println("row count is " + rowCount);
    
    	}
    	
    
    
    }
    


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Bitstream or PCM?
    centos7安装Redis-3.2.8
    【生肉】【不义联盟
    ES6中Map数据结构学习笔记
    机器学习基石入门
    2019/5/9 长难句
    文件遍历选取脚本
    [JS奇怪的世界]No.55 危險小叮嚀:陣列與for in
    OpenGL Panorama Player
    吴裕雄--天生自然MySQL学习笔记:MySQL 连接
  • 原文地址:https://www.cnblogs.com/jamesf/p/4751458.html
Copyright © 2011-2022 走看看