HBase coprocessor Statistics Row count

Source: Internet
Author: User

Environment: cdh5.1.0


Enable CoprocessorMethod 1.

Enable Coprocessor Aggregation (enable coprocessor Aggregation)
We have two methods: 1. Start the global aggregation and be able to manipulate the data on all the tables. By modifying the Hbase-site.xml file, you only need to add the following code:

<property>   <name>hbase.coprocessor.user.region.classes</name>   <value> Org.apache.hadoop.hbase.coprocessor.aggregateimplementation</value> </property>

Enable CoprocessorMethod 2.

Enable table aggregation, which only takes effect for a specific table. Implemented through the HBase Shell.


(1) Disable the specified table. hbase> Disable ' mytable '


(2) Add aggregation hbase> alter ' mytable ', METHOD = ' Table_att ', ' coprocessor ' and ' = ' | org.apache.hadoop.hbase.coprocessor.aggregateimplementation| | '


(3) Restart the specified table hbase> enable ' mytable '


Code:

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");p rivate static final byte[] CF = Bytes.tobytes ("BD");p ublic static void Main (string[] args) throws Throwable {Configuration customconf = new configuration (); Customconf.set ("Hbase.zookeeper.quorum", "192.168.58.101");//Increase RPC communication duration customconf.setlong ("Hbase.rpc.timeout" , 600000);//Set Scan cache Customconf.setlong ("hbase.client.scanner.caching", 1000); Configuration configuration = Hbaseconfiguration.create (customconf); Aggregationclient aggregationclient = NEW aggregationclient (configuration); Scan scan = new scan ();//Specifies the Scan column family, unique value 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);}}


HBase coprocessor Statistics Row count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.