hbase shell插入根据条件查询数据

hbase shell插入根据条件查询数据

创建并插入数据:

hbase(main):179:0> create 'scores','grade','course'

hbase(main):180:0> put 'scores','zhangsan01','course:art','90'

hbase(main):181:0> scan 'scores'
ROW                                                          COLUMN+CELL                                                                                                                                                                     
 zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            
1 row(s) in 0.0150 seconds

hbase(main):182:0> put 'scores','zhangsan01','course:math','99',1498003561726
(这里手动设置时间戳的时候一定不能大于你当前的系统时间,否则的话无法删除该数据,我这里手动设置数据是为了下面的DependentColumnFilter过滤器试验。你可以查看一下插入第一条数据的时间戳,再插入第二条数据的时间戳为第一条数据的时间戳)
hbase(main):183:0> put 'scores','zhangsan01','grade:','101'
问题:当我将这条插入的数据删除之后再执行put 'scores','zhangsan01','grade:','101',1498003561726后能成功却scan 'scores'后没有该条数据,而再执行put 'scores','zhangsan01','grade:','101'后scan 'scores'却能查到该条数据。如果想插入该条数据的时候手动设置时间戳的话,必须在第一次插入该条数据或者truncate后再插入。
hbase(main):184:0> put 'scores','zhangsan02','course:art','90'

hbase(main):185:0> get 'scores','zhangsan02','course:art'
COLUMN                                                       CELL                                                                                                                                                                            
 course:art                                                  timestamp=1498003601365, value=90                                                                                                                                               
1 row(s) in 0.0080 seconds

hbase(main):186:0> put 'scores','zhangsan02','grade:','102',1498003601365
hbase(main):187:0> put 'scores','zhangsan02','course:math','66',1498003561726
hbase(main):188:0> put 'scores','lisi01','course:math','89',1498003561726
hbase(main):189:0> put 'scores','lisi01','course:art','89'
hbase(main):190:0> put 'scores','lisi01','grade:','201',1498003561726

查询数据:
根据rowkey查询:

hbase(main):187:0> get 'scores','zhangsan01'
COLUMN                                                       CELL                                                                                                                                                                            
 course:art                                                  timestamp=1498003561726, value=90                                                                                                                                               
 course:math                                                 timestamp=1498003561726, value=99                                                                                                                                               
 grade:                                                      timestamp=1498003593575, value=101                                                                                                                                              
3 row(s) in 0.0160 seconds

根据列名查询:
hbase(main):188:0> scan 'scores',{COLUMNS=>'course:art'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     
 lisi01                                                      column=course:art, timestamp=1498003655021, value=89                                                                                                                            
 zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            
 zhangsan02                                                  column=course:art, timestamp=1498003601365, value=90                                                                                                                            
3 row(s) in 0.0120 seconds

查询两个rowkey之间的数据:
hbase(main):205:0> scan 'scores',{STARTROW=>'zhangsan01',STOPROW=>'zhangsan02'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     
 zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            
 zhangsan01                                                  column=course:math, timestamp=1498003561726, value=99                                                                                                                           
 zhangsan01                                                  column=grade:, timestamp=1498003593575, value=101                                                                                                                               
1 row(s) in 0.0140 seconds

查询两个rowkey且根据列名来查询:
hbase(main):206:0> scan 'scores',{COLUMNS=>'course:art',STARTROW=>'zhangsan01',STOPROW=>'zhangsan02'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     
 zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            
1 row(s) in 0.0110 seconds

查询指定rowkey到末尾根据列名的查询:
hbase(main):207:0> scan 'scores',{COLUMNS=>'course:art',STARTROW=>'zhangsan01',STOPROW=>'zhangsan09'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     
 zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            
 zhangsan02                                                  column=course:art, timestamp=1498003601365, value=90                                                                                                                            
2 row(s) in 0.0310 seconds

上一篇:【Android群英传】学习笔记(二)


下一篇:HBase的java操作,最新API。(查询指定行、列、插入数据等)