HappyBase - Is there an equivalent of find_one or scan_one?

1k views Asked by At

All the rows in a particular HBase table that I am making a UI for happen to have the same columns and will have so for the foreseeable future. I would like my html data visualizer application to simply query for a single random row to take note of the column names, and put this list of column names into a variable to refer to throughout the program.

I didn't see any equivalent to find_one or scan_one in the docs for HappyBase.

What is the best way to accomplish this?

3

There are 3 answers

0
wouter bolsterlee On BEST ANSWER

This will fetch only the first row:

row = next(table.scan(limit=1))

Additionally you can specify a filter string to avoid retrieving the values, which is only worthwile if your values are large and you're performing this query often.

0
Oussama Jilal On

You can create a Scanner object, without specifying the start row (so that it start at the first row in the table), and limit the scan to one row. You will get then the first row only.

From the HBase shell command it should look like this:

scan 'table_name', {LIMIT => 1}

I don't know for HappyBase but I think you should be able to do that

0
kennyut On

I use the 'limit' option. Here is my HappyBase Python code:

pool1 = happybase.ConnectionPool(size=2, host='172.00.00.01')
with pool1.connection() as conn1:
    hTable = conn1.table('HBastTableHere')
    for rowKey, rowData in hTable.scan(  limit=1):
        print rowData