1

我已将 byte[] 作为 rowKey 放在 HBase 表中。现在我希望能够根据我使用的字节检索行。如果我使用 HBase shell,我会执行以下操作:

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

现在,我想在使用其余客户端的 Java 类 GetMyRow.java 中获取该行。我的代码如下所示:

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);

我收到以下错误:

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)

任何想法如何根据构成 rowKey 的字节获取一行?

4

1 回答 1

0

当然看起来像一个编码问题。查看 REST 客户端的源代码,它最终调用:

Bytes.toStringBinary()

在产生以下形式的十六进制字符串的关键字节上:

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

它看起来不像 url 对字符串进行编码,也许“\”会导致 httpclient 问题。如果是这种情况,很可能是 hbase REST 客户端中的一个错误。更高版本的 hbase 可能已修复此问题。

于 2012-08-06T15:37:27.350 回答