简体   繁体   English

如何在HBase列中存储原始数据类型,字符串并使用序列化和反序列化检索它们?

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

How to store Primitive Datatypes , Strings in a HBase Column and Retrieve Them. 如何在HBase列中存储原始数据类型,字符串并检索它们。 Normally when we want to store data in HBase table we do as below. 通常,当我们要将数据存储在HBase表中时,请执行以下操作。

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. 我的问题是如何在包括字符串的HBase中存储基本数据类型,以及如何使用序列化和反序列化检索它们。 I'm really new to HBase and please give me a clear steps to get this job done. 我真的是HBase的新手,请给我明确的步骤以完成此工作。

check out my answer here 在这里查看我的答案

You can use Bytes in org.apache.hadoop.hbase.util 您可以在org.apache.hadoop.hbase.util使用Bytes

like: 喜欢:

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

long l = Bytes.toLong(longBytes); 

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM