HBase 常用Shell命令(二)

 

  1. hbase(main):079:0> create 'scores',{NAME=>'course',VERSIONS=>2}
  2. 0 row(s) in 0.9590 seconds
  3.  hbase(main):080:0> put 'scores','Tom','course:math','97'
  4. 0 row(s) in 0.0100 seconds

 

 
  1. hbase(main):081:0> scan 'scores'
  2. ROW COLUMN+CELL
  3. Tom column=course:math, timestamp=1394097631387, value=97
  4. 1 row(s) in 0.0190 seconds
  5. hbase(main):082:0> put 'scores','Tom','course:math','100'
  6. 0 row(s) in 0.0080 seconds
  7. hbase(main):026:0> scan 'scores'
  8. ROW COLUMN+CELL
  9. Tom column=course:math, timestamp=1394097651029, value=100
  10. 1 row(s) in 0.0110 seconds
  11. hbase(main):027:0> scan 'scores',{TIMERANGE=>[1394097631387,1394097651029]}
  12. ROW COLUMN+CELL
  13. Tom column=course:math, timestamp=1394097631387, value=97
  14. 1 row(s) in 0.0210 seconds
  15. hbase(main):028:0> scan 'scores',{TIMERANGE=>[1394097631387,1394097651030]}
  16. ROW COLUMN+CELL
  17. Tom column=course:math, timestamp=1394097651029, value=100
  18. 1 row(s) in 0.0100 seconds

从上面可以看到,HBASE默认scan出来的结果是最后一条时间戳的记录,那么如何把这两条都scan出来呢,
这时候可以加入VERSIONS这个约束条件:

  1. hbase(main):032:0> scan 'scores',{VERSIONS=>2}
  2. ROW COLUMN+CELL
  3. Tom column=course:math, timestamp=1394097651029, value=100
  4. Tom column=course:math, timestamp=1394097631387, value=97
  5. 1 row(s) in 0.0130 seconds

 上面的命令,已经把这条记录都scan出来了。

再看下面的例子:

 

 

  1. scan 'scores',{TIMERANGE=>[1394097631386,1394097651029],VERSIONS=>2}
  2. ROW COLUMN+CELL
  3.  Tom column=course:math, timestamp=1394097631387, value=97
  4. 1 row(s) in 0.0130 seconds

 从上面的结果只scan出一条记录。可知,TIMERANGE表示的是”>=开始时间 and <结束时间“的。再看:

  1. hbase(main):003:0> scan 'scores',{TIMERANGE=>[1394097631386,1394097651030],VERSIONS=>2}
  2. ROW COLUMN+CELL
  3.  Tom column=course:math, timestamp=1394097651029, value=100
  4.  Tom column=course:math, timestamp=1394097631387, value=97
  5. 1 row(s) in 0.0100 seconds

 OK,这样就明白了
 不过上面的加了VERSIONS=>2,就可以查到历史的数据了,但是必须再创建表的时候加上VERSIONS,否则无效,看下面的例子:

 

  1. hbase(main):082:0> create 'member','address','info'
  2. 0 row(s) in 0.4140 seconds
  3. => Hbase::Table - member

 

  1. hbase(main):093:0> put 'member','wanglei','info:age','24'
  2. 0 row(s) in 0.0730 seconds

 

 

  1. hbase(main):093:1>get 'member','wanglei',{COLUMN=>'info:age'}
  2. COLUMN         CELL
  3.  info:age timestamp=1394438746187, value=24
  4. hbase(main):093:7> put 'member','wanglei','info:age','99'
  5. 0 row(s) in 0.0730 seconds
  6. hbase(main):093:18> get 'member','wanglei',{COLUMN=>'info:age'}
  7. COLUMN                             CELL
  8. info:age                          timestamp=1394439539837, value=100 
 
     

 

 
  1. hbase(main):022:0> get 'member','wanglei',{COLUMN=>'info:age',TIMERANGE=>[1394438746187,1394439539838],VERSIONS=>2}
  2. COLUMN CELL
  3.  info:age imestamp=1394439539837, value=100
  4. 1 row(s) in 0.0050 seconds

 可以看到,虽然加了VERSIONS,但get的结果是1条;这就是因为建表时默认的VERSION是1.
修改VERSIONS:

 

  1. hbase(main):029:0> alter 'member',{NAME=>'info','VERSIONS'=>2}
  2. Updating all regions with the new schema...
  3. 0/1 regions updated.
  4. 1/1 regions updated.
  5. Done.
  6. 0 row(s) in 2.1680 seconds

 

 
 
  1. hbase(main):046:0> put 'member','wanglei','info:age','101'
  2. 0 row(s) in 0.0590 seconds
  3. hbase(main):047:0> get 'member','wanglei',{COLUMN=>'info:age'}
  4. COLUMN CELL
  5.  info:age timestamp=1394441161595, value=101
  6. 1 row(s) in 0.0120 seconds

   那么现在就可以把倆条记录get出来了,如下:
  

  1. hbase(main):049:0> get 'member','wanglei',{COLUMN=>'info:age',TIMERANGE=>[1394439539837,1394441161596],VERSIONS=>2}
  2. COLUMN CELL
  3.  info:age timestamp=1394441161595, value=101
  4.  info:age timestamp=1394439539837, value=100
  5. 2 row(s) in 0.0080 seconds

 

你可能感兴趣的:(shell命令)