Hbase byteArray 到 Long
Hbase byteArray to Long
我有一个像这样创建的行键
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 的第一部分和第二部分。
谢谢
您保存您的多头价值错误的方式!
因为当您使用 +
时,您的包含 long 值字节的数组会转换为字符串,转换后的值显示 字节数组在内存中的当前地址, 不是它的值!
正确的储蓄方式:
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))
我有一个像这样创建的行键
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 的第一部分和第二部分。
谢谢
您保存您的多头价值错误的方式!
因为当您使用 +
时,您的包含 long 值字节的数组会转换为字符串,转换后的值显示 字节数组在内存中的当前地址, 不是它的值!
正确的储蓄方式:
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))