Create Namespace

hbase(main):001:0> list_namespace
NAMESPACE
default
hbase
2 row(s) in 0.1410 seconds

list_namespace 로 namespace 목록을 확인할 수 있으며

hbase(main):008:0> create_namespace 'sample_data'
0 row(s) in 0.0140 seconds

create_namespace 로 namespace를 만들 수 있다.

Create Table

hbase(main):005:0> create 'test', 'user', 'time', 'etc'
0 row(s) in 2.2290 seconds

=> Hbase::Table - test

여기서 test 는 Rowkey, user , time , etc 는 Column Family(이하 CF)이다. CF아래에는 여러개의 Column이 들어갈 수 있다.

Table 확인

hbase(main):006:0> list 'test'
TABLE
test
1 row(s) in 0.0110 seconds

=> ["test"]
hbase(main):007:0> describe 'test'
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => 'etc', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCAC
HE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'time', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCA
CHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'user', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCA
CHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
3 row(s) in 0.0210 seconds

Put(Insert)

hbase(main):008:0> put 'test', 'row1', 'user:user_id', '201512340'
0 row(s) in 0.0500 seconds

hbase(main):009:0> scan 'test'
ROW                                                   COLUMN+CELL
 row1                                                 column=user:user_id, timestamp=1649474477502, value=201512340
1 row(s) in 0.0130 seconds
hbase(main):011:0> put 'test', 'row1', 'user:user_session', 11112222
0 row(s) in 0.0050 seconds

hbase(main):012:0> scan 'test'
ROW                                                   COLUMN+CELL
 row1                                                 column=user:user_id, timestamp=1649474477502, value=201512340
 row1                                                 column=user:user_session, timestamp=1649474623589, value=11112222
1 row(s) in 0.0090 seconds
hbase(main):013:0> put 'test', 'row1', 'time:event_time', '2015-02-03 15:00:000'
0 row(s) in 0.0050 seconds

hbase(main):014:0> scan 'test'
ROW                                                   COLUMN+CELL
 row1                                                 column=time:event_time, timestamp=1649474683141, value=2015-02-03 15:00:000
 row1                                                 column=user:user_id, timestamp=1649474477502, value=201512340
 row1                                                 column=user:user_session, timestamp=1649474623589, value=11112222
1 row(s) in 0.0140 seconds

기본적으로 put <Table>, <Rowkey>, <CF:Column>, <Value> 의 문법이다. hbase shell 의 put 으로는 Row안의 한 값만 한번에 넣을 수 있다(CELL에 삽입).

만약 2개 이상의 value를 넣으려고 하면 다음과 같이 에러가 발생한다.

hbase(main):010:0> put 'test', 'row1', 'user:user_id', '201512340', 'user:user_session', '11112222'

ERROR: no method 'add' for arguments (org.jruby.java.proxies.ArrayJavaProxy,org.jruby.java.proxies.ArrayJavaProxy,org.jruby.RubyString,org.jruby.java.proxies.ArrayJavaProxy) on Java::OrgApacheHadoopHbaseClient::Put
  available overloads:
    (byte[],java.nio.ByteBuffer,long,java.nio.ByteBuffer)
    (byte[],byte[],long,byte[])

Here is some help for this command:
Put a cell 'value' at specified table/row/column and optionally
timestamp coordinates.  To put a cell value into table 'ns1:t1' or 't1'
at row 'r1' under column 'c1' marked with the time 'ts1', do:

  hbase> put 'ns1:t1', 'r1', 'c1', 'value'
  hbase> put 't1', 'r1', 'c1', 'value'
  hbase> put 't1', 'r1', 'c1', 'value', ts1
  hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
  hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
  hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}

The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:

  hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}

scan <table>

hbase(main):014:0> scan 'test'
ROW                                                   COLUMN+CELL
 row1                                                 column=time:event_time, timestamp=1649474683141, value=2015-02-03 15:00:000
 row1                                                 column=user:user_id, timestamp=1649474477502, value=201512340
 row1                                                 column=user:user_session, timestamp=1649474623589, value=11112222
1 row(s) in 0.0140 seconds