How can i store and retrieve primitive data types using hbase api.? My task is to save random events on hbase that contains unpredictable data types which are generated randomly. and need to retrieve them after whenever i want? can someone help me out this please. because i'm really new to hbase and this stuff.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is how you put data into a HBase table :
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, "TABLE_NAME");
Put p = new Put(rowKey);
p.add(Bytes.toBytes("cf"), Bytes.toBytes("c1"), Bytes.toBytes("VALUE"));
table.put(p);
You don't have to worry about the type of the data. However, you need to keep in mind that anything which goes inside HBase goes as an array of bytes. So, while fetching the data back from HBase you need to convert it back into the suitable type because you will be getting a bytearray everytime. This can be done using various overloaded methods provided by the Bytes class. Like this :
Bytes.toString(byte[])
Bytes.toFloat(byte[])
Bytes.toLong(byte[])