我有一个像这样创建的行键
Put put = new Put(Bytes.toBytes(tweets.getContact_Unique_Id()+"^"+Bytes.toBytes(epoch)));
其中 epoch 是长时间戳。
现在,当我扫描时,我得到一行
3857^[B@7c8f4424
现在我想将 rowkey ie 的部分转换为 Long
[B@7c8f4424
我如何实现这一目标。
编辑 -> 如果我使用 put 作为
Put put = new Put(Bytes.toBytes(tweets.getContact_Unique_Id() + "^" + epoch);
并非所有行都会被插入,但是当我使用时
Put put = new Put(Bytes.toBytes(tweets.getContact_Unique_Id()+"^"+Bytes.toBytes(epoch)));
所有行都会被插入,请注意所有时间值都不同。
另请注意,我使用“^”分隔 rowkey 的第一部分和第二部分。
谢谢
最佳答案
您以错误的方式保存了您的多头值(value)!
因为当您使用 +
时,将 long 值的字节数组转换为字符串,转换后的值显示字节数组的内存中的当前地址,不是它的值(value)!
正确的保存方式:
Put put = new Put(Bytes.add(Bytes.toBytes(tweets.getContact_Unique_Id() + "^"), Bytes.toBytes(epoch))); //I kept "^", don't know why you need it
并检索:
// row is the byte array of your key
// Bytes.tail(..) gets tail of key's bytes with bytes of your long
// Bytes.toLong(..) converts long bytes to long
// 8 corresponds to long size in bytes
Bytes.toLong(Bytes.tail(row, 8))
关于java - Hbase byteArray 转 Long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38095801/