Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store hierarchical data in hbase

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

like image 285
Infinity Avatar asked Nov 17 '11 20:11

Infinity


1 Answers

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!!!

like image 66
sriram Avatar answered Sep 20 '22 12:09

sriram