Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

I need to get data from hbase table for a given date range

I need to get data from hbase table for a given date range

New Contributor

I am using below scan statement in Hbase to obtain data from a table wherein the column A30 should be between the given date range.How can this be achieved, as below query pulls up record beyond range of 01-JUN-2011 and 30-JUN-2011.

scan 'mytable',{FILTER => "SingleColumnValueFilter('cf1','A15',=, 'binary:10') AND SingleColumnValueFilter('cf1','F49' ,=, 'binary:6') AND SingleColumnValueFilter('cf1','A30',>=, 'binary:01-JUN-2011') AND SingleColumnValueFilter('cf1','A30',<=, 'binary:30-JUN-2011')"}

Data in hbase table ;-

column=cf1:A30, timestamp=1487080632072, value=15-JAN-14

2 REPLIES 2

Re: I need to get data from hbase table for a given date range

Super Guru

@joseph c

HBase stores data is stored in bytes. The date you have stored 15-JAN-14 is definitely less than 30-JUN-2011 lexicographically. It is however, smaller than 01-JUN-2011 because JAN is less than JUN (at least that's what it seems). May be put the two date condition in brackets. But, please remember, what you are doing is not really a date comparison as far as HBase is concerned. It is a string comparison.

if you want to do proper date comparisons. then you should store timestamps instead of date as a string. or use this format "20110630".

Re: I need to get data from hbase table for a given date range

Super Guru
@joseph c

actually on a second thought, I realize 15-JAN-14 is also greater than 01-JUN-2011 because 15 is greater than 01 and it is less than 30-JUN-2011 because 15 is less than 30. HBase is behaving exactly how it is supposed to behave. You need to store date in a different format, like YYYYMMDD. When you do that, 20140115 does not fall between 20110601 and 20110630 lexicographically and you will get your expected result.

Another way is to convert Date to timestamp.