mirsik
mirsik

Reputation: 1091

Hbase scan operation: How to provide a conditional end row instead of an exact row key?

The row key is in the following format:

UserID-ResourceID

I know that the rows in Hbase are sorted, which is why I have the row key format shown above. Resources belonging to the same user will be stacked together. Lets say that the UserID is random, but ResourceID is a simple counter and is incremented each time a new resource is added.

Now to get resources, I do not want to scan the whole table which is why I want to provide a start row and an end row. I can provide the start row since I know the UserID and I know that ResourceID starts at 0, but I do not know how many resources there are,(or I do not want to store that information). Can I provide a condition, which if is not valid, should stop the scan? Something like if the UserID changes then stop scanning.

Essentially, I want it to find the first resource belonging to that person and then walk down the list, since all resources are stacked together, and finish after all the resources have been found.


Follow-on-question: is it possible to provide a condition so that it only returns a subset of the resources such as the last 10 resources belonging to that person in the list.

Upvotes: 1

Views: 763

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

For your first question, this is what I do (and I should note that the start and stop row you provide to the scanner do not have to be real):

I open a scanner and provide the start row as UserID- and the stop row as UserID. (the trick is that when you look at an ASCII table, the dot (.) is just after the dash (-), so when it finishes with all the rows starting with UserID- the scanner stops)

This way you don't need to know that actual first resource or even the last one, you just need to know the user

As for your second question, There are some things called Filters that you can add to your scanner, and they can do lots of things, but none of them has a way to get only the 10 last rows

Upvotes: 1

Related Questions