[英]How to store Primitive Datatypes , Strings in a HBase Column and Retrieve Them Using Serialization and Deserialization?
如何在HBase列中存储原始数据类型,字符串并检索它们。 通常,当我们要将数据存储在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();
我的问题是如何在包括字符串的HBase中存储基本数据类型,以及如何使用序列化和反序列化检索它们。 我真的是HBase的新手,请给我明确的步骤以完成此工作。
在这里查看我的答案
您可以在org.apache.hadoop.hbase.util
使用Bytes
喜欢:
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.