hbase bytearray到long

uwopmtnx  于 2021-06-09  发布在  Hbase
关注(0)|答案(1)|浏览(433)

我有一个这样创建的行键

  1. Put put = new Put(Bytes.toBytes(tweets.getContact_Unique_Id()+"^"+Bytes.toBytes(epoch)));

其中epoch是长时间戳。
现在当我扫描时,我得到一行
3857^[b@7c8f4424
现在我想把rowkey的部分转换成long
[b@7c8f4424
我如何做到这一点。
编辑->如果我使用put as
put put=新put(bytes.tobytes(tweets.getcontact\u unique\u id()+“^”+epoch);
不是所有的行都被插入,但是当我使用
put put=new put(bytes.tobytes(tweets.getcontact_unique_id()+“^”+bytes.tobytes(epoch));
插入所有行,请注意所有时间值都不同。
另外请注意,我用“^”分隔了rowkey的第一部分和第二部分。
谢谢

igetnqfo

igetnqfo1#

你以错误的方式保存你的长期价值!
因为当你使用 + 你的数组用字节的长值转换成字符串,转换后的值显示的是内存中字节数组的当前地址,而不是它的值!
正确的保存方法:

  1. Put put = new Put(Bytes.add(Bytes.toBytes(tweets.getContact_Unique_Id() + "^"), Bytes.toBytes(epoch))); //I kept "^", don't know why you need it

和检索:

  1. // row is the byte array of your key
  2. // Bytes.tail(..) gets tail of key's bytes with bytes of your long
  3. // Bytes.toLong(..) converts long bytes to long
  4. // 8 corresponds to long size in bytes
  5. Bytes.toLong(Bytes.tail(row, 8))

相关问题