3

I am using SingleColumnValueFilter, scan, getScanner, and retrieving the values from hbase table. The values being resulted is sorted in the row Id-vise. But I want the result to be sorted in the value-vise.

Example:

Hbase Table:
RowId | col1:amount | col1:balance
  1         5000         1000
  2         3000         1500
  3         4000          500

Now, When I select amount in the Web UI (which I customized). Then, Result should be sorted in amount-vise.

Expected Result after chosen amount column:

RowId | **col1:amount** | col1:balance
  2         3000         1500
  3         4000          500
  1         5000         1000
Balaji
  • 757
  • 7
  • 16

1 Answers1

3

If you want to sort things value wise- unfortunately that won't happen in HBase. HBase sorts your data by row key and it does so lexicographically.

What you need to do is create a secondary index where the rowKey incorporates the value. In your case the value is numeric, so you'll have to zero pad your numbers to get the lexicographical sorting to work properly.

Here's how you could structure your secondary index:

Hbase Table:
RowId | col1:amount | col1:balance
  val000500         rowID         3
  val001000         rowID         1
  val001500         rodID         2

When you GET the secondary index, it will return the row ID of your original data. Use that row ID to get the rest of your data from the original record.

Tucker
  • 7,017
  • 9
  • 37
  • 55
  • 2
    Whether you know how to create secondary index using coprocessor. Can you share some piece of code. – Balaji Jul 11 '12 at 05:48