hbase_user
hbase_user

Reputation: 529

How to list all row keys in an hbase table?

How do I list all row keys in an hbase table?

I need to do this using PHP with a REST interface.

Upvotes: 2

Views: 10231

Answers (4)

Nicolas Spiegelberg
Nicolas Spiegelberg

Reputation: 131

I don't know what the REST interface is like, but you probably want to filter some data out client-side to avoid large RPC responses. You can do this by adding server-side filters to your scan:

Scan s = new Scan();
FilterList fl = new FilterList();
// returns first instance of a row, then skip to next row
fl.addFilter(new FirstKeyOnlyFilter());
// only return the Key, don't return the value
fl.addFilter(new KeyOnlyFilter());
s.setFilter(fl);

HTable myTable;
ResultScanner rs = myTable.getScanner(s);
Result row = rs.next();
while (row != null) ...

http://svn.apache.org/repos/asf/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/filter/

Upvotes: 4

kyle jeske
kyle jeske

Reputation: 41

This...

http://localhost:8080/tablename/*/columnfamily:columnid 

...will return all values in your table relative to that column in that table, sort of like applying column filter in the scanner.

Also, if you're looking for multiple columns - separate them with a comma.

So: /tablename/*/columnfamily:columnid,columnfamily:columnid2

Upvotes: 4

David
David

Reputation: 3261

If you are listing all of the keys in an HBase table, then you are using the wrong tool. HBase is for large data systems where it is impractical to list all of the keys.

What may be more sensible is to start at a given key and list the next N keys (for values of N less than 10K). There are nice Java interfaces for doing this type of thing with a scan -- setting a start key and/or an end key.

Most HBase functionality is exposed via the Thrift interface. I would suggest looking there

Upvotes: 5

hbase_user
hbase_user

Reputation: 529

I have found a way..

http://localhost:8080/tablename/* will return an xml data and i can preg-match it to get the rows.

Inviting better suggestions..

Upvotes: 4

Related Questions