6

我是 hbase 的新手。你能告诉我如何将列添加到列族。我有这样的数据:

{
name: abc
addres: xyz
}

我与列族人进行了表格测试。如何将姓名和地址作为一列添加到此人。请在 hbase 命令行和 java 中显示我。

4

2 回答 2

15

HBase 外壳:

来自 Hbase shell wiki:http ://hbase.apache.org/book.html#shell

在指定的表/行/列和可选的时间戳坐标处放置一个单元格“值”。要将单元格值放入标有时间 'ts1' 的列 'c1' 下的行 'r1' 的表 't1' 中,请执行以下操作:

hbase> put 't1', 'r1', 'c1', 'value', ts1

在你的情况下是这样的:

hbase> put 'test', 'yourRow', 'person:name', 'abc'
hbase> put 'test', 'yourRow', 'person:address', 'xyz'

在 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);
于 2012-09-12T22:05:16.270 回答
6

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.

于 2012-09-14T13:51:28.267 回答