HBase KeyValue.getKey() 返回额外字符
以下 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你想调用 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.