Reputation: 359
I have a hbase table with 1 column (Expense) and where date is the row key.
How do i get all the records for the past 5 days? Assuming today's date is 2014-04-13? Which filter to use?
I have the data as below
rowkey Expense
2014-04-13 128
2014-04-12 57
2014-04-11 10
2014-04-10 100
2014-04-09 797
2014-04-08 67
2014-04-07 56
2014-04-06 14
Upvotes: 2
Views: 4334
Reputation: 21
According to the documentation setMaxResultSize is probably not what you want:
public Scan setMaxResultSize(long maxResultSize)
Set the maximum result size. The default is -1; this means that no specific maximum result size will be set for this scan, and the global configured value will be used instead. (Defaults to unlimited).
Parameters: maxResultSize - The maximum result size in bytes.
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html#setMaxResultSize-long-
You can either use fixed start- and stop-keys, or you could work with a combination of PageFilter and setCaching.
Upvotes: 2
Reputation: 21663
mashuai's answer will work just fine, but just to offer an alternative, you can also do a reverse scan:
Scan scan = new Scan();
scan.setReversed(true);
scan.setMaxResultSize(5);
Upvotes: 3
Reputation: 551
You don't need filter. Assuming today is 2014-04-13, you can set start row as 2014-04-09 and the stop row as 2014-04-14. like that
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes("2014-04-09"));
scan.setStopRow(Bytes.toBytes("2014-04-14"));
Upvotes: 3