Sean Nguyen
Sean Nguyen

Reputation: 13168

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.

Upvotes: 7

Views: 30732

Answers (2)

Jean-Philippe Bond
Jean-Philippe Bond

Reputation: 10679

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);

Upvotes: 15

Arnon Rotem-Gal-Oz
Arnon Rotem-Gal-Oz

Reputation: 25929

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.

Upvotes: 6

Related Questions