2

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

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hbase_user
  • 529
  • 4
  • 9
  • 16
  • 1
    possible duplicate of [how to list all row keys in an hbase table?](http://stackoverflow.com/questions/5218085/how-to-list-all-row-keys-in-an-hbase-table) – CanSpice Mar 22 '11 at 20:46
  • 1
    It's a dup of what hbase_user tried to ask in the other question... but it's not a dup of what was actually asked (or answered). – mdahlman Jan 28 '12 at 06:08

4 Answers4

5

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

David
  • 3,251
  • 18
  • 28
  • Hi David,thanks for the reply. I was experimenting with REST interface and found some ways to scan a table within the limits. Unfortunately its not working as it should be in my cluster. If i go back and search for Thrift, it will kill lot of my working hours! If you have any nice working way to connect hbase and php using REST interface, please come up and help me! – hbase_user Mar 11 '11 at 05:24
4

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..

hbase_user
  • 529
  • 4
  • 9
  • 16
4

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/

4

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

Oussama Jilal
  • 7,669
  • 2
  • 30
  • 53
kyle jeske
  • 41
  • 1