Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add column to column family in hbase

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.

like image 241
Sean Nguyen Avatar asked Sep 12 '12 21:09

Sean Nguyen


People also ask

How do I add a column family to an existing HBase table?

Simply press the "+" button in the "Alter table" page and add your new column family with all settings you need.

What is HBase column family?

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.

Which command is applied for adding new column family in a table along with versions for an existing table?

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.


2 Answers

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);
like image 124
Jean-Philippe Bond Avatar answered Sep 16 '22 12:09

Jean-Philippe Bond


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.

like image 24
Arnon Rotem-Gal-Oz Avatar answered Sep 17 '22 12:09

Arnon Rotem-Gal-Oz