I am new to hbase. Can you show me how to add column to a column family. I have data like this:
{
name: abc
addres: xyz
}
I have a table test with column family person. How can I add name and address as a column to this person. Please show me in hbase command line as well as java.
Simply press the "+" button in the "Alter table" page and add your new column family with all settings you need.
An HBase table contains column families , which are the logical and physical grouping of columns. There are column qualifiers inside of a column family, which are the columns. Column families contain columns with time stamped versions. Columns only exist when they are inserted, which makes HBase a sparse database.
You can add a column family to a table using the method addColumn() of HBAseAdmin class. Follow the steps given below to add a column family to a table.
HBase Shell :
From the Hbase shell wiki : http://hbase.apache.org/book.html#shell
Put a cell 'value' at specified table/row/column and optionally timestamp coordinates. To put a cell value into table 't1' at row 'r1' under column 'c1' marked with the time 'ts1', do:
hbase> put 't1', 'r1', 'c1', 'value', ts1
something like this in your case :
hbase> put 'test', 'yourRow', 'person:name', 'abc'
hbase> put 'test', 'yourRow', 'person:address', 'xyz'
In Java :
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "test");
Put p = new Put(Bytes.toBytes("yourRow"));
p.add(Bytes.toBytes("person"), Bytes.toBytes("name"),
Bytes.toBytes("abc"));
table.put(p);
JP Bond gave you the sample code you need - I just wanted to add that one of the nice things about HBase is since it is sparse (i.e. doesn't reserve column space for rows with out values). One of the features for this design decision is that you can create a new column (column family + qualifier) just by writing for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With