HBase Query Summary: Narrow the scope first, then use the regular filter

Source: Internet
Author: User
Tags regular expression table name

Recent presentation of data analysis results. Purpose: Save in, take out, seemingly simple actually not easy. After these days of unremitting efforts finally found the middle-class HBase key design method.
Key Design: Time + Type one + type two + (the maximum of long-the value of this data) + ...
Query Code:

/** * Filter out the interval according to Startrowkey and Endrowkey and then isolate the final result according to the Regxkey regular match and num * @param tableName table name * @param startrowkey start range * @param en Drowkey End Range * @param regxkey regular match * @param num query number of bars * @return list<result> */public list<result> Getnumreg Exrow (String tablename,string startrowkey,string endrowkey, string Regxkey,int num) {htableinterface table = null
        ;
        list<result> list = null;
            try {table = htablepool.gettable (tableName);
            Create a filter container and set its relationship (and/or) filterlist fl = new filterlist (FilterList.Operator.MUST_PASS_ALL);
            Set the regular filter regexstringcomparator rc = new Regexstringcomparator (Regxkey);
            RowFilter RF = new RowFilter (compareop.equal, RC);
            Filter gets the number of bars filter filternum = new Pagefilter (num),//per page of display bar//filter add fl.addfilter (RF);
            Fl.addfilter (Filternum);
            Scan scan = new scan (); Set range of Values scan. Setstartrow (Startrowkey.getbytes ());//Start Key Scan.setstoprow (Endrowkey.getbytes ());//end of key scan.
            SetFilter (FL);//Set filter for query list Resultscanner scanner = Table.getscanner (scan);
            List = new arraylist<result> ();
            for (Result Rs:scanner) {list.add (RS);
        }} catch (Exception e) {e.printstacktrace ();

            } finally {try {table.close ();
            } catch (IOException e) {e.printstacktrace ();
    }} return list; }

Examples of testing:

list<result> list = Hbaseutil.getnumregexrow ("Student", "201611241440vmhardware.disk.read.bps", " 201611241440vmhardware.disk.read.bpsa "," 201611241440vmhardware\\.disk\\.read\\.bps.* ", 100);

Principle:
The ①hbase will be sorted by default based on the key value, so our data will be sorted by the first time, then sorted by type, then by type two, and then by the way value is from big to small (you should know ~ ~).
② Range 201611241440vmhardware.disk.read.bps to 201611241440vmhardware.disk.read.bpsa because a is larger than any number
③201611241440vmhardware\.disk\.read\.bps.* represents the regular expression you want to spell on demand
④100 is the number of data you want to take (from big to small).

Hope to help everyone ~ ~ (have not understood the place or the error/suggestion welcome message points out)

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.