当前位置:   article > 正文

HBase shell详情_nameerror: undefined local variable or method `nul

nameerror: undefined local variable or method `null' for main:object

概述

HBase 为用户提供了一个非常方便的使用方式,我们称之为"HBase Shell"。

HBase Shell提供了大多数的HBase命令,通过HBase Shell用户可以方便地创建、删除及修改表,还可以向表中添加数据、列出表中的相关信息等。

备注:写错HBase Shell命令时用键盘上的"Ctrl+Backspace"进行删除,"Backspace" 不起作用,另外结尾不能有任何符号。

在启动HBase之后,用户可以通过下面的命令进入HBase Shell之中,命令如下图所示:

  1. [root@liaozhongmin5 local]# hbase shell
  2. HBase Shell; enter 'help<RETURN>' for list of supported commands.
  3. Type "exit<RETURN>" to leave the HBase Shell
  4. Version 0.94.7, r1471806, Wed Apr 24 18:44:36 PDT 2013
  5. hbase(main):001:0>
具体的HBase Shell命令如下表所示:



一般操作

1.查看服务器状态

  1. hbase(main):028:0> status
  2. 1 servers, 0 dead, 6.0000 average load
  3. hbase(main):029:0>

2.查看HBase版本

  1. hbase(main):029:0> version
  2. 0.94.7, r1471806, Wed Apr 24 18:44:36 PDT 2013
  3. hbase(main):030:0>

DDL操作

1.create 命令

创建一个具有三个列族"member_id"和"address"即"info"的表"member",其中表名、行和列都要用单引号括起来,并以逗号隔开。

  1. hbase(main):025:0> create 'member','member_id','address','info'
  2. 0 row(s) in 1.1320 seconds
  3. hbase(main):026:0>

注:语句最后不能有分号,加入不小心多写了个分号,则可以使用qui命令退出错误控制台,如下:

  1. hbase(main):030:0> list;
  2. hbase(main):031:0*
  3. hbase(main):032:0* qui
  4. TABLE
  5. member
  6. membermember_id
  7. scores
  8. tb_myHbase
  9. users
  10. 5 row(s) in 0.1300 seconds
  11. NameError: undefined local variable or method `qui' for #<Object:0x1046270>
  12. hbase(main):033:0>


2.list命令

查看当前HBase中具有哪些表

  1. hbase(main):026:0> list
  2. TABLE
  3. member
  4. scores
  5. tb_myHbase
  6. users
  7. 4 row(s) in 0.0520 seconds
  8. hbase(main):027:0>


3.describe 命令

查看表的描述信息。

  1. hbase(main):028:0> describe 'member'
  2. DESCRIPTION ENABLED
  3. 'member', {NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SC true
  4. OPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP
  5. _DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', B
  6. LOCKCACHE => 'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLI
  7. CATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '21474836
  8. 47', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK =>
  9. 'true', BLOCKCACHE => 'true'}, {NAME => 'member_id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER =>
  10. 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TT
  11. L => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCO
  12. DE_ON_DISK => 'true', BLOCKCACHE => 'true'}
  13. 1 row(s) in 0.0320 seconds
  14. hbase(main):029:0>

4.删除一个列族:disable,alter,enable

我们之前建了3个列族,如果觉得member_id这个列族是多余的,要将其删除。

alter 'member','delete'=>'member_id'

会出现如下错误:

ERROR: org.apache.hadoop.hbase.TableNotDisabledException: org.apache.hadoop.hbase.TableNotDisabledException: member
解决方案:先disable这张表

  1. hbase(main):004:0> disable 'member'
  2. 0 row(s) in 2.0960 seconds
  3. hbase(main):005:0>
删除刚才的列族

alter 'member','delete'=>'member_id'
查看表情况

  1. hbase(main):017:0> describe 'member'
  2. DESCRIPTION ENABLED
  3. 'member', {NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SC false
  4. OPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP
  5. _DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', B
  6. LOCKCACHE => 'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLI
  7. CATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '21474836
  8. 47', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK =>
  9. 'true', BLOCKCACHE => 'true'}
  10. 1 row(s) in 0.0490 seconds
我们可以发现member_id字段已经被删除了。

启用表

  1. hbase(main):021:0> enable 'member'
  2. 0 row(s) in 2.0860 seconds



5.删除一个表 disable,drop

先disable表,再drop删除表,然后用list检查

  1. hbase(main):022:0> disable 'member'
  2. 0 row(s) in 2.1140 seconds
  3. hbase(main):023:0> drop 'member'
  4. 0 row(s) in 1.1670 seconds
  5. hbase(main):024:0> list
  6. TABLE
  7. scores
  8. tb_myHbase
  9. users
  10. 3 row(s) in 0.0250 seconds
  11. hbase(main):025:0>

6.查询表是否存在

  1. hbase(main):026:0> exists 'member'
  2. Table member does not exist
  3. 0 row(s) in 0.0740 seconds
  4. hbase(main):027:0>

7.判断表是否enable

  1. hbase(main):028:0> is_enable 'users'
  2. NoMethodError: undefined method `is_enable' for #<Object:0x735f45>
  3. hbase(main):029:0> is_enabled 'users'
  4. true
  5. 0 row(s) in 0.0060 seconds
  6. hbase(main):030:0> disable 'users'
  7. 0 row(s) in 2.0880 seconds
  8. hbase(main):031:0> is_enabled 'users'
  9. false
  10. 0 row(s) in 0.0040 seconds
  11. hbase(main):032:0>
注:另外还有一个命令与他对应即判断是否disable:is_disabled '表名'



DML操作

1.插入数据

  1. put 'member','scutshuxue','info:age','24'
  2. put 'member','scutshuxue','info:birthday','1987-06-17
  3. put 'member','scutshuxue','info:company','alibaba'
  4. put 'member','scutshuxue','address:contry','china'
  5. put 'member','scutshuxue','address:province','zhejiang'
  6. put 'member','scutshuxue','address:city','hangzhou'
  7. put 'member','xiaofeng','info:birthday','1987-4-17'
  8. put 'member','xiaofeng','info:favorite','movie'
  9. put 'member','xiaofeng','info:company','alibaba'
  10. put 'member','xiaofeng','address:contry','china'
  11. put 'member','xiaofeng','address:province','guangdong'
  12. put 'member','xiaofeng','address:city','jieyang'
  13. put 'member','xiaofeng','address:town','xianqiao'
注:插入语句后面一定不要有空格。


2.获取一条数据

  1. hbase(main):012:0> get 'member','xiaofeng'
  2. COLUMN CELL
  3. address:city timestamp=1423056496524, value=jieyang
  4. address:contry timestamp=1423056496475, value=china
  5. address:province timestamp=1423056496496, value=guangdong
  6. address:town timestamp=1423056499535, value=xianqiao
  7. info:birthday timestamp=1423056496348, value=1987-4-17
  8. info:company timestamp=1423056496447, value=alibaba
  9. info:favorite timestamp=1423056496386, value=movie
  10. 7 row(s) in 0.0780 seconds
  11. hbase(main):013:0>

3.获取一条记录中某个列族的信息

  1. hbase(main):013:0> get 'member','xiaofeng','info'
  2. COLUMN CELL
  3. info:birthday timestamp=1423056496348, value=1987-4-17
  4. info:company timestamp=1423056496447, value=alibaba
  5. info:favorite timestamp=1423056496386, value=movie
  6. 3 row(s) in 0.0160 seconds
  7. hbase(main):014:0>

4.获取一条记录的某个列族中的某个列的信息

  1. hbase(main):015:0> get 'member','xiaofeng','info:company'
  2. COLUMN CELL
  3. info:company timestamp=1423056496447, value=alibaba
  4. 1 row(s) in 0.0130 seconds
  5. hbase(main):016:0>


5.更新一条记录

把xiaofeng的年龄改为25岁

  1. hbase(main):001:0> get 'member','xiaofeng','info:age'
  2. COLUMN CELL
  3. info:age timestamp=1423057077614, value=23
  4. 1 row(s) in 0.7080 seconds
  5. hbase(main):002:0> put 'member','xiaofeng','info:age','25'
  6. 0 row(s) in 0.0180 seconds
  7. hbase(main):003:0> get 'member','xiaofeng','info:age'
  8. COLUMN CELL
  9. info:age timestamp=1423057248381, value=25
  10. 1 row(s) in 0.0110 seconds
  11. hbase(main):004:0>

6.根据TimeStamp来获取记录

  1. hbase(main):007:0> get 'member','xiaofeng',{column=>'info:age',timestamp=>1423057248381}
  2. NameError: undefined local variable or method `column' for #<Object:0x1046270>
  3. hbase(main):008:0> get 'member','xiaofeng',{COLUMN=>'info:age',TIMESTAMP=>1423057248381}
  4. COLUMN CELL
  5. info:age timestamp=1423057248381, value=25
  6. 1 row(s) in 0.0070 seconds
注:要注意大小写,另外TIMESTAMP后面的时间戳不用单引号。

7.根据版本号获取记录

  1. hbase(main):025:0> get 'member','xiaofeng',{COLUMN=>'info:company',VERSION=>3}
  2. COLUMN CELL
  3. info:company timestamp=1423056496447, value=alibaba
  4. 1 row(s) in 0.0100 seconds
  5. hbase(main):026:0>



8.全表扫描

  1. hbase(main):009:0> scan 'member'
  2. ROW COLUMN+CELL
  3. lavimer column=address:city, timestamp=1423056054519, value=ganzhou
  4. lavimer column=info:name, timestamp=1423056214559, value=liaozhongmin
  5. scutshuxue column=address:city, timestamp=1423056496301, value=hangzhou
  6. scutshuxue column=address:contry, timestamp=1423056399271, value=china
  7. scutshuxue column=address:province, timestamp=1423056496250, value=zhejiang
  8. scutshuxue column=info:age, timestamp=1423056337733, value=24
  9. scutshuxue column=info:birthday, timestamp=1423056367576, value=1987-06-17
  10. scutshuxue column=info:company, timestamp=1423056370340, value=alibaba
  11. xiaofeng column=address:city, timestamp=1423056496524, value=jieyang
  12. xiaofeng column=address:contry, timestamp=1423056496475, value=china
  13. xiaofeng column=address:province, timestamp=1423056496496, value=guangdong
  14. xiaofeng column=address:town, timestamp=1423056499535, value=xianqiao
  15. xiaofeng column=info:age, timestamp=1423057248381, value=25
  16. xiaofeng column=info:birthday, timestamp=1423056496348, value=1987-4-17
  17. xiaofeng column=info:company, timestamp=1423056496447, value=alibaba
  18. xiaofeng column=info:favorite, timestamp=1423056496386, value=movie
  19. 3 row(s) in 0.1090 seconds
  20. hbase(main):010:0>

9.删除某条记录中某个列族的某个列

删除xiaofeng年龄这一列。

  1. hbase(main):010:0> delete 'member','xiaofeng','info:age'
  2. 0 row(s) in 0.0060 seconds
  3. hbase(main):011:0> get 'member','xiaofeng','info:age'
  4. COLUMN CELL
  5. 0 row(s) in 0.0330 seconds
  6. hbase(main):012:0> get 'member','xiaofeng','info'
  7. COLUMN CELL
  8. info:birthday timestamp=1423056496348, value=1987-4-17
  9. info:company timestamp=1423056496447, value=alibaba
  10. info:favorite timestamp=1423056496386, value=movie
  11. 3 row(s) in 0.0470 seconds
  12. hbase(main):013:0>


10.删除整行

  1. hbase(main):013:0> deleteall 'member','scutshuxue'
  2. 0 row(s) in 0.0080 seconds
  3. hbase(main):014:0> scan 'member'
  4. ROW COLUMN+CELL
  5. lavimer column=address:city, timestamp=1423056054519, value=ganzhou
  6. lavimer column=info:name, timestamp=1423056214559, value=liaozhongmin
  7. xiaofeng column=address:city, timestamp=1423056496524, value=jieyang
  8. xiaofeng column=address:contry, timestamp=1423056496475, value=china
  9. xiaofeng column=address:province, timestamp=1423056496496, value=guangdong
  10. xiaofeng column=address:town, timestamp=1423056499535, value=xianqiao
  11. xiaofeng column=info:birthday, timestamp=1423056496348, value=1987-4-17
  12. xiaofeng column=info:company, timestamp=1423056496447, value=alibaba
  13. xiaofeng column=info:favorite, timestamp=1423056496386, value=movie
  14. 2 row(s) in 0.0430 seconds
  15. hbase(main):015:0>

11.查询表中有多少行

  1. hbase(main):015:0> count 'member'
  2. 2 row(s) in 0.2170 seconds
  3. hbase(main):016:0>

12.给某条记录的某个列族增加一列并使用counter实现递增

  1. hbase(main):018:0> incr 'member','xiaofeng','info:age'
  2. COUNTER VALUE = 1
  3. hbase(main):019:0> get 'member','xiaofeng','info:age'
  4. COLUMN CELL
  5. info:age timestamp=1423058331353, value=\x00\x00\x00\x00\x00\x00\x00\x01
  6. 1 row(s) in 0.0100 seconds
  7. hbase(main):021:0> incr 'member','xiaofeng','info:age'
  8. COUNTER VALUE = 2
  9. hbase(main):022:0>

13.获取当前count的值

  1. hbase(main):022:0> get_counter 'member','xiaofeng','info:age'
  2. COUNTER VALUE = 2
  3. hbase(main):023:0>


14.清空整张表

  1. hbase(main):026:0> truncate 'member'
  2. Truncating 'member' table (it may take a while):
  3. - Disabling table...
  4. - Dropping table...
  5. - Creating table...
  6. 0 row(s) in 5.5960 seconds
  7. hbase(main):027:0> scan 'member'
  8. ROW COLUMN+CELL
  9. 0 row(s) in 0.0150 seconds
  10. hbase(main):028:0>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/725756
推荐阅读
相关标签
  

闽ICP备14008679号