How to store Primitive Datatypes , Strings in a HBase Column and Retrieve Them Using Serialization and Deserialization?

醉酒当歌 提交于 2020-01-21 10:35:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!