How to store primitive data types, rows in an HBase column and retrieve them using serialization and deserialization?

How to store primitive data types, rows in an HBase column and retrieve them. Usually, when we want to store data in an HBase table, we do as shown below.

Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, "people");
Put put = new Put(Bytes.toBytes("doe-john-m-12345"));
put.add(Bytes.toBytes("personal"), Bytes.toBytes("givenName"), Bytes.toBytes("John"));
put.add(Bytes.toBytes("personal"), Bytes.toBytes("mi"), Bytes.toBytes("M"));
put.add(Bytes.toBytes("personal"), Bytes.toBytes("surame"), Bytes.toBytes("Doe"));
put.add(Bytes.toBytes("contactinfo"), Bytes.toBytes("email"), Bytes.toBytes("john.m.doe@gmail.com"));
table.put(put);
table.flushCommits();
table.close();

My question is how to store primitive data types in HBase, including strings, and how to retrieve them using serialization and deletion. I am really new to HBase and please give me clear steps to get the job done.

0
source share
1 answer

check my answer here

You can use Bytesinorg.apache.hadoop.hbase.util

like:

byte[] longBytes = Bytes.toBytes(2l);

long l = Bytes.toLong(longBytes); 

System.out.println(l); // <-- this should give you 2l 
0

Source: https://habr.com/ru/post/1772834/


All Articles