1
votes

I am planning to store streaming weather data in HBase. My rowkey is: [5 letter city code][timestamp] where timestamp is [date][time as in HH:mm:ss.SSS] and I have just one column called "temperature". So sample data would look like:

NEWYO20131121080932123 32.4  
NEWYO20131121081034342 34.6  
NEWYO20131121081156424 31.8  
NEWYO20131121081223532 24.9  
SINGA20131121091142563 23.1  
SANFR20131121091214763 22.1 

I want to query data to return me temperature values in New York between 8:11 and 8:13 on 21st November (rows 3 and 4 should be returned)

How do I write a query for this using the Java API.

I came across Scan(byte[] startRow, byte[] stopRow), but I don't think that I can use that, since I don't know the exact rowkey while retrieving data (because of the seconds and the milliseconds at the end of the key)

(Is it possible to use regex for rowkeys?)

2

2 Answers

1
votes

you can use RowFilter. The following code will help

Filter filter2 = new RowFilter(CompareFilter.CompareOp.EQUAL,
new RegexStringComparator("regex"));
scan.setFilter(filter2);
ResultScanner scanner2 = table.getScanner(scan);
for (Result res : scanner2) {
   System.out.println(res);
}
0
votes

startkey is NEWYO20131121081100000
endkey is NEWYO20131121081400000

BTW: There is no need to use hbase native API. you can check http://phoenix.incubator.apache.org/
or https://github.com/zhang-xzhi/simplehbase