Note: This page is out of date. It was written with respect
to the distribution of HBase in hadoop-0.16.0.
Assuming HBase is installed and running, type hbase
shell to start up HBase Shell. You'll see something like:
Hbase Shell, 0.0.2 version. Copyright (c) 2007 by udanax, licensed to Apache Software Foundation. Type 'help;' for usage. hql >
Now, issue the following command:
hql > create table 'test' ('family1', 'family2');
Columns in HBase are grouped into "column families". The above command creates a table named "test" that has two column families, "family1" and "family2".
Now issue the following command:
hql > insert into 'test' ('family1:col1', 'family2:col1') values ('abc', 'def') where row = '1';
Columns in HBase are uniquely identified as x:y, where x is the column family and y is the column name. In the command above, we've inserted some values into "family1:col1" and "family2:col1". Now we can query:
hql > select * from 'test'; 08/03/21 21:14:15 INFO hbase.HTable: Creating scanner over test starting at key +-------------------------+-------------------------+-------------------------+ | Row | Column | Cell | +-------------------------+-------------------------+-------------------------+ | 1 | family1:col1 | abc | +-------------------------+-------------------------+-------------------------+ | 1 | family2:col1 | def | +-------------------------+-------------------------+-------------------------+ 1 row(s) in set. (0.13 sec)
Let's add some more columns and rows:
hql > insert into 'test' ('family1:col2', 'family2:col2') values ('123', '456') where row = '1';
hql > insert into 'test' ('family1:col1', 'family1:col2', 'family2:col1', 'family2:col2') values ('HBase', 'is', 'very', 'cool') where row = '2';
Now we can issue some queries:
hql > select 'family1:col1' from 'test'; 08/03/21 21:19:39 INFO hbase.HTable: Creating scanner over test starting at key +--------------------------------------+--------------------------------------+ | Row | Cell | +--------------------------------------+--------------------------------------+ | 1 | abc | +--------------------------------------+--------------------------------------+ | 2 | HBase | +--------------------------------------+--------------------------------------+ 2 row(s) in set. (0.12 sec) hql > select * from 'test' where row = '1'; +--------------------------------------+--------------------------------------+ | Column | Cell | +--------------------------------------+--------------------------------------+ | family1:col1 | abc | +--------------------------------------+--------------------------------------+ | family1:col2 | 123 | +--------------------------------------+--------------------------------------+ | family2:col1 | def | +--------------------------------------+--------------------------------------+ | family2:col2 | 456 | +--------------------------------------+--------------------------------------+ 1 row(s) in set. (0.03 sec)
Now you have an idea of what HBase is all about!