user1576754
user1576754

Reputation: 21

hbase rest client get

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?

Upvotes: 2

Views: 971

Answers (1)

Paul M
Paul M

Reputation: 2046

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.

Upvotes: 0

Related Questions