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)