java - Hbase byteArray to Long -
i have row key being created
put put = new put(bytes.tobytes(tweets.getcontact_unique_id()+"^"+bytes.tobytes(epoch)));
where epoch long timestamp.
now when scan row
3857^[b@7c8f4424
now wish convert part of rowkey ie long
[b@7c8f4424
how achieve this.
edit -> if use put
put put = new put(bytes.tobytes(tweets.getcontact_unique_id() + "^" + epoch);
not rows gets inserted , when use
put put = new put(bytes.tobytes(tweets.getcontact_unique_id()+"^"+bytes.tobytes(epoch)));
all rows gets inserted , please note time values different.
also note have used "^" seperate out 1st , 2nd part of rowkey.
thanks
you save long value in a wrong way!
because when use +
array bytes of long value converts string, converted value shows the current address in memory of bytes array, not value!
the correct way of saving:
put put = new put(bytes.add(bytes.tobytes(tweets.getcontact_unique_id() + "^"), bytes.tobytes(epoch))); //i kept "^", don't know why need
and retrieving:
// row byte array of key // bytes.tail(..) gets tail of key's bytes bytes of long // bytes.tolong(..) converts long bytes long // 8 corresponds long size in bytes bytes.tolong(bytes.tail(row, 8))
Comments
Post a Comment