在hbase中存储分层数据的最佳方法 [英] Best way to store hierarchical data in hbase
问题描述
我有从客户端接收到的分层XML文件,我需要将它存储在Hbase数据库中,因为我是Hbase的新手,我无法理解如何处理,请你引导我如何继续进行分层数据存储到Hbase。
预先致谢
Hbase商店数据列明智格式。每个记录必须具有唯一的密钥。子列可以在飞行中创建,但不能在主列上创建。
例如condider this xml。
< X1>
< X2 name =uniqueid> 1< / X2>
< X3>
< X4> value1< / X4>
< X5> value2< / X5>
< X6>
< X7> value3< / x7>
< X8> value4< / X8>
< / X6>
< / X3>
< X7> value5< / X7>
< / X1>
在这种情况下,主列族将是X3和X7。行ID可以从X2中获取。
您可以使用java api来构造一个相当于此的Hbase条目,比如,
Put p = new Put(/ *放置唯一的行ID * /.getBytes());
p.add(X3.getBytes(),X4.getBytes(),value1.getBytes());
其中第一个参数是列族,第二个参数称为列限定符(子列) 。
你也可以使用2个参数构造函数,如
$ p $ p 。新增( X3:X6:X7 .getBytes(),值3);
然后 table.put(p)
。这就是它!!!
I have a hierarchical XML file received from client, i need to store it in Hbase database, as i am new to the Hbase i not able to understand how to approach, can you please guide me how should i proceed for this hierarchical data storage to Hbase.
Thanks in advance
Hbase stores data in Column wise format. Each record must have a unique key. The sub columns can be created on the fly but not the main columns.
For example condider this xml.
<X1>
<X2 name = "uniqueid">1</X2>
<X3>
<X4>value1</X4>
<X5>value2</X5>
<X6>
<X7>value3</X7>
<X8>value4</X8>
</X6>
</X3>
<X7>value5</X7>
</X1>
In this case, the main column family would be X3 and X7. Row Id can be taken from X2. You can construct a Hbase entry equivalent to this using java api like,
Put p = new Put("/*put the unique row id */ ".getBytes() );
p.add("X3".getBytes(), "X4".getBytes(), value1.getBytes());
where the first argument is the column family and the second one is called the column qualifier(sub column).
You can also use 2 argument constructor like,
p.add("X3:X6:X7".getBytes(),value3);
then table.put(p)
. Thats it!!!
这篇关于在hbase中存储分层数据的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!