hbase实现快速行统计

1. Enable AggregationClient coprocessor

You have two choices :

You can enable aggregation coprocessor on all your tables by adding the following lines tohbase-site.xml :

 <property>
   <name>hbase.coprocessor.user.region.classes</name>
   <value>org.apache.hadoop.hbase.coprocessor.AggregateImplementation</value>
 </property>
or ...you can enable coprocessor only on a table throught the HBase shell :

1. disable the table
hbase> disable 'mytable'

2. add the coprocessor
hbase> alter 'mytable', METHOD => 'table_att','coprocessor'=>'|org.apache.hadoop.hbase.coprocessor.AggregateImplementation||'

3. re-enable the table

hbase> enable 'mytable'

2. Increase RPC timeout (opt)

In some cases the following exception could be raised : 
java.net.SocketTimeoutException: Call to node2/55.37.68.154:60020 failed on socket timeout exception
On large table or if you are expecting slow I/O this might be necessary:

 <property>
   <name>hbase.rpc.timeout</name>
   <value>300000</value>
 </property>
n.b. : you can also specify this property directly in the client source code, see next section

3. ''RowCount' Snippet

  1. public class MyAggregationClient {  
  2.   
  3.     private static final byte[] TABLE_NAME = Bytes.toBytes("mytable");  
  4.     private static final byte[] CF = Bytes.toBytes("d");  
  5.   
  6.     public static void main(String[] args) throws Throwable {  
  7.   
  8.         Configuration customConf = new Configuration();  
  9.         customConf.setStrings("hbase.zookeeper.quorum",  
  10.                 "node0,node1,node2");  
  11.         // Increase RPC timeout, in case of a slow computation  
  12.         customConf.setLong("hbase.rpc.timeout"600000);  
  13.         // Default is 1, set to a higher value for faster scanner.next(..)  
  14.         customConf.setLong("hbase.client.scanner.caching"1000);  
  15.         Configuration configuration = HBaseConfiguration.create(customConf);  
  16.         AggregationClient aggregationClient = new AggregationClient(  
  17.                 configuration);  
  18.         Scan scan = new Scan();  
  19.         scan.addFamily(CF);  
  20.         long rowCount = aggregationClient.rowCount(TABLE_NAME, null, scan);  
  21.         System.out.println("row count is " + rowCount);  
  22.   
  23.     }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值