简体   繁体   中英

how to scan hbase table when unix timestamp is part of the rowkey?

we have hbase table with row key as AccountId and unixtimestamp.

eg: ACNTID1359694800000

Account Id: ACNTID
unixtimestamp: 1359694800000

1359694800000 is the value for 2/1/2013

I am looking for a query for Account Ids on a give date? can i use startrow, stop row logic. Any other ways?

You are on the right track. The startrow is inclusive and the end row is exclusive. So just add 1 to the unix timestamp on the end row and you are set.

scan 'mytable', {STARTROW => 'ACNTID1359694800000', ENDROW => 'ACNTID1359694800001'}

Your rowkey structure doesn't support getting account id's for any given unix timestamp, since the timestamp in your case is in the righter most part of the rowkey or atleast not using STARTROW & STOPROW alone. To get the desired result, your query should scan all rowkeys of the table and do the filtering for the given timestamp . HBase comes with a Filter called RowFilter , used along with Scan , to restrict the rows returned by HBase. Since you store the rowkey as text, you can use SubStringComparator or RegexStringComparator along with the RowFilter . The command line equivalent of this is,

scan 'table_name', { FILTER =>"RowFilter(=,'substring:1359694800000')"}

The above command will return all rows that has 1359694800000 in their rowkey.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM