1、创建test,如果存在先删除
hbase(main):010:0> disable 'test' 0 row(s) in 1.4250 seconds hbase(main):011:0> drop 'test' 0 row(s) in 0.5540 seconds hbase(main):012:0> create 'test','grade', 'course' 0 row(s) in 0.7450 seconds => Hbase::Table - test
2、查看数据表
hbase(main):013:0> list TABLE test 2 row(s) in 0.0200 seconds
3、查看数据表结构
hbase(main):015:0> describe 'test' DESCRIPTION ENABLED 'test', {NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REP true LICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY = > 'false', BLOCKCACHE => 'true'}, {NAME => 'grade', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NO NE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZ E => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'} 1 row(s) in 0.0630 seconds
4、插入数据
(1) 加入一行数据,行名称为zkb 列族grad的列名为”” 值位5 hbase(main):006:0> put 'test','zkb','grade:','5' 0 row(s) in 0.0420 seconds (2) 给zkb这一行的数据的列族course添加一列<math,97> hbase(main):007:0> put 'test','zkb','course:math','97' 0 row(s) in 0.0270 seconds (3) 给zkb这一行的数据的列族course添加一列<art,87> hbase(main):008:0> put 'test','zkb','course:art','87' 0 row(s) in 0.0260 seconds (4) 加入一行数据,行名称为baoniu 列族grad的列名为”” 值为4 hbase(main):009:0> put 'test','baoniu','grade:','4' 0 row(s) in 0.0260 seconds (5) 给baoniu这一行的数据的列族course添加一列<math,89> hbase(main):010:0> put 'test','baoniu','course:math','89' 0 row(s) in 0.0270 seconds (6) 给Jerry这一行的数据的列族course添加一列<art,80> hbase(main):011:0> put 'test','baoniu','course:art','80' 0 row(s) in 0.0270 seconds
5、查看一条数据
hbase(main):028:0> get 'test','zkb' COLUMN CELL course:art timestamp=1417327162462, value=87 course:math timestamp=1417327154780, value=97 grade: timestamp=1417326981345, value=5 3 row(s) in 0.0200 seconds
6、查看所有数据
hbase(main):029:0> scan 'test' ROW COLUMN+CELL baoniu column=course:art, timestamp=1417327239480, value=80 baoniu column=course:math, timestamp=1417327233828, value=89 baoniu column=grade:, timestamp=1417327206239, value=4 zkb column=course:art, timestamp=1417327162462, value=87 zkb column=course:math, timestamp=1417327154780, value=97 zkb column=grade:, timestamp=1417326981345, value=5 2 row(s) in 0.0130 seconds
7、指定搜索条件的查询,startrow和stoprow,一般程序开发都使用它
hbase(main):030:0> scan 'test',{STARTROW=>'baoniu', STOPROW=>'zkb'} ROW COLUMN+CELL baoniu column=course:art, timestamp=1417327239480, value=80 baoniu column=course:math, timestamp=1417327233828, value=89 baoniu column=grade:, timestamp=1417327206239, value=4 1 row(s) in 0.0230 seconds
8、查看指定列的数据
hbase(main):037:0> scan 'test',{STARTROW=>'baoniu', STOPROW=>'zkb', COLUMNS=>'course'} ROW COLUMN+CELL baoniu column=course:art, timestamp=1417327239480, value=80 baoniu column=course:math, timestamp=1417327233828, value=89 1 row(s) in 0.0160 seconds
9、添加filter
命令行: scan 'nd_shop_rpt_new_d',{STARTROW=>'2014-11-05', STOPROW=>'2014-11-29', FILTER => "( SingleColumnValueFilter('t', 'shop_id', =, 'binary:100705598') AND SingleColumnValueFilter('t', 'auction_id', =, 'binary:42516637646'))"}
hbase(main):012:0> scan 'nd_shop_rpt_new_d',{STARTROW=>'2014-11-05', STOPROW=>'2014-11-29', FILTER => "( SingleColumnValueFilter('t', 'shop_id', =, 'binary:100705598') AND SingleColumnValueFilter('t', 'auction_id', =, 'binary:42516637646'))"} ROW COLUMN+CELL 2014-11-22_100705598_42516637646 column=t:auction_new_time, timestamp=1417348934182, value= 2014-11-22_100705598_42516637646 column=t:auction_shelf_time, timestamp=1417348934182, value=2014-11-21 14:00:05 2014-11-22_100705598_42516637646 column=t:cat_id, timestamp=1417348934182, value=121452038 2014-11-22_100705598_42516637646 column=t:cat_name, timestamp=1417348934182, value= 2014-11-22_100705598_42516637646 column=t:seller_id, timestamp=1417348934182, value=-99 2014-11-22_100705598_42516637646 column=t:shop_id, timestamp=1417348934182, value=100705598 2014-11-22_100705598_42516637646 column=t:thedate, timestamp=1417348934182, value=2014-11-22 2014-11-22_100705598_42516637646 column=t:trade_amount, timestamp=1417348934182, value=1 2014-11-22_100705598_42516637646 column=t:trade_amt, timestamp=1417348934182, value=68.0 2 row(s) in 1.4770 seconds