问题
How to store Primitive Datatypes , Strings in a HBase Column and Retrieve Them. Normally when we want to store data in HBase table we do as 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 derialization. I'm really new to HBase and please give me a clear steps to get this job done.
回答1:
check out my answer here
You can use Bytes
in org.apache.hadoop.hbase.util
like:
byte[] longBytes = Bytes.toBytes(2l);
long l = Bytes.toLong(longBytes);
System.out.println(l); // <-- this should give you 2l
来源:https://stackoverflow.com/questions/24236547/how-to-store-primitive-datatypes-strings-in-a-hbase-column-and-retrieve-them-u