HBase KeyValue.getKey() 返回额外字符

发布于 2024-12-14 10:14:51 字数 1061 浏览 1 评论 0原文

以下 hBase 代码在 rowKey 的前面返回一些奇怪的字符:

“\u0000”“\u0014”“ei:虾:-749......”

前面的奇怪字符是“\u0000”和“\u0014”,有时是“\u0016”。我在上面的行中加了引号以使其可读。只有两个,它们被添加到我的 rowkey 之前。密钥应该是“ei:shrimp:-749...”。这是我用来取回密钥的代码:

import static org.apache.hadoop.hbase.util.Bytes.toBytes;

List<KeyValue> kvs = result.list();
        String key = null;
        for (KeyValue kv : kvs) {
            String value = Bytes.toString(kv.getValue());
            String qualifier = Bytes.toString(kv.getQualifier());
            if(key == null) {
                key = Bytes.toString(kv.getKey());

这是我用来创建我的 put 的代码:

public Put createPut(String columnFamily) {
        StringBuilder sb = new StringBuilder(this.getGroup()).append(':');
        sb.append(this.getKey()).append(':').append(this.getCoordinateHash());

        Put p = new Put(toBytes(sb.toString()));
        p = p.add(toBytes(columnFamily), toBytes(COLUMN_VALUE), toBytes(this.getValue()));

知道那些奇怪的字符是什么吗?我做错了什么? 谢谢你, 拉贾特

the following hBase code returns some weird characters on the front of my rowKey:

"\u0000""\u0014""ei:shrimp:-749…."

The prepended weird characters are '\u0000' and '\u0014', and sometimes '\u0016'. I put quotes in the above line to make it readable. There are only two and they're prepended to my rowkey. The key should be 'ei:shrimp:-749...'. Here is the code that I use to get the keys back:

import static org.apache.hadoop.hbase.util.Bytes.toBytes;

List<KeyValue> kvs = result.list();
        String key = null;
        for (KeyValue kv : kvs) {
            String value = Bytes.toString(kv.getValue());
            String qualifier = Bytes.toString(kv.getQualifier());
            if(key == null) {
                key = Bytes.toString(kv.getKey());

Here is the code I used to create my put:

public Put createPut(String columnFamily) {
        StringBuilder sb = new StringBuilder(this.getGroup()).append(':');
        sb.append(this.getKey()).append(':').append(this.getCoordinateHash());

        Put p = new Put(toBytes(sb.toString()));
        p = p.add(toBytes(columnFamily), toBytes(COLUMN_VALUE), toBytes(this.getValue()));

Any idea what those weird characters are? What am I doing wrong?
Thank you,
Rajat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待圉鍢 2024-12-21 10:14:51

我猜你想调用 KeyValue.getRow()。

KeyValue.getKey() 返回原始键,前两个字节是一个 Short,指示行的长度。

I guess you want to call KeyValue.getRow().

KeyValue.getKey() returns the raw key, and the first two bytes are a Short that indicates how long the row is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文