hbase rest client get

Tag: get , hbase Author: yan8850973 Date: 2012-07-19

I have put byte[] as rowKey in an HBase table. Now I want to be able to retrieve the rows based on the bytes that I used. If I use the HBase shell, I do the following:

get 'table', "\x12\x00\x00\x00\x03\x03" and it works fine.

Now I want to fetch that row inside a Java class, GetMyRow.java, that uses the rest client. My code looks like this:

byte[] rowKey = new byte[6];
rowKey[0] = 0x12;
rowKey[1] = 0x00;
rowKey[2] = 0x00;
rowKey[3] = 0x00;
rowKey[4] = 0x03;
rowKey[5] = 0x03;
Get g = new Get(rowKey);
Result r = table.get(g);

And I get the following error:

org.apache.commons.httpclient.URIException: escaped absolute path not valid
    at org.apache.commons.httpclient.URI.setRawPath(URI.java:2837)
    at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2023)
    at org.apache.commons.httpclient.URI.<init>(URI.java:167)
    at org.apache.hadoop.hbase.rest.client.Client.executePathOnly(Client.java:115)
    at org.apache.hadoop.hbase.rest.client.Client.execute(Client.java:164)
    at org.apache.hadoop.hbase.rest.client.Client.get(Client.java:284)
    at org.apache.hadoop.hbase.rest.client.Client.get(Client.java:257)
    at org.apache.hadoop.hbase.rest.client.Client.get(Client.java:242)
    at org.apache.hadoop.hbase.rest.client.RemoteHTable.get(RemoteHTable.java:267)
    at udf.HBaseConnector.main(GetMyRow.java:74)

Any ideas how to fetch a row based on the bytes that makeup the rowKey?

which version of hbase? Are you able to get it to work if you use a key with only printable characters?
Yes, it works with all other data types.
I am using HBase Version 0.90.4-cdh3u3.

Other Answer1

Certainly looks like an encoding issue. Looking at the source for the REST client, it winds up calling:

Bytes.toStringBinary()

on the key bytes which produces hex string of the form:

\x12\x00\x00\x00\x03\x03

it doesn't look like it ever url encodes the string and maybe the "\" are causing httpclient problems. If this is the case, it is probably a bug in the hbase rest client. Its possible that later versions of hbase have fixed this.

comments:

I switched from using RemoteHTable to HTable and now it works fine.
that's an option if your clients will have access to your entire cluster