Shell 数据定义
create: 用于创建一个表。
create 'order','info','user'
create 'userlog','info','params','result'
list: 用于列出HBase的所有表。
hbase(main):009:0> list
TABLE
order
userlog
2 row(s)
Took 0.0088 seconds
=> ["order", "userlog"]
disable: 用于禁用表。
hbase(main):011:0> disable 'order'
Took 1.7366 seconds
is_disabled: 用于验证表是否被禁用。
hbase(main):012:0> is_disabled 'order'
true
Took 0.0235 seconds
=> 1
enable: 用于启用一个表。
hbase(main):014:0> enable 'order'
Took 1.4490 seconds
is_enabled: 用于验证表是否已启用。
hbase(main):017:0> is_enabled 'order'
true
Took 0.0319 seconds
=> true
describe: 用于提供了一个表的描述。
hbase(main):019:0> describe 'order'
alter: 用于改变一个表。
exists: 用于验证表是否存在。
hbase(main):020:0> exists 'order'
Table order does exist
Took 0.0125 seconds
=> true
drop: 用于从HBase中删除表。
drop 'test'
drop_all: 用于丢弃在命令中给出匹配“regex”的表。
Shell 数据操作
put: 用于把指定列在指定的行中单元格的值在一个特定的表。
put ‘table name’,’row ’,'Column family:column name',’new value’
示例
put 'order','1001', 'info:price',15
get: 用于取行或单元格的内容。
hbase(main):024:0> get 'order',1001
delete:用于删除表中的单元格值。
deleteall: 用于删除给定行的所有单元格。
scan: 用于扫描并返回表数据。
hbase(main):026:0> scan 'order'
条件查询
# 查询指定列的数据
scan 'order', {COLUMNS=> 'baseInfo:birthday'}
除了列 (COLUMNS) 修饰词外,HBase 还支持 Limit(限制查询结果行数),STARTROW(ROWKEY 起始行,会先根据这个 key 定位到 region,再向后扫描)、STOPROW(结束行)、TIMERANGE(限定时间戳范围)、VERSIONS(版本数)、和 FILTER(按条件过滤行)等。
如下代表从 rowkey2 这个 rowkey 开始,查找下两个行的最新 3 个版本的 name 列的数据:
scan 'order', {COLUMNS=> 'baseInfo:name',STARTROW => 'rowkey2',STOPROW => 'wrowkey4',LIMIT=>2, VERSIONS=>3}
条件过滤
Filter 可以设定一系列条件来进行过滤。如我们要查询值等于 24 的所有数据:
scan 'order', FILTER=>"ValueFilter(=,'binary:24')"
值包含 yale 的所有数据:
scan 'order', FILTER=>"ValueFilter(=,'substring:yale')"
列名中的前缀为 birth 的:
scan 'order', FILTER=>"ColumnPrefixFilter('birth')"
FILTER 中支持多个过滤条件通过括号、AND 和 OR 进行组合:
# 列名中的前缀为birth且列值中包含1998的数据
scan 'order', FILTER=>"ColumnPrefixFilter('birth') AND ValueFilter ValueFilter(=,'substring:1998')"
PrefixFilter 用于对 Rowkey 的前缀进行判断:
scan 'order', FILTER=>"PrefixFilter('wr')"
status: 提供HBase的状态,例如,服务器的数量。
hbase(main):001:0> status
1 active master, 1 backup masters, 3 servers, 0 dead, 1.0000 average load
version: 提供正在使用HBase版本。
hbase(main):002:0> version
2.2.4, r67779d1a325a4f78a468af3339e73bf075888bac, 2020年 03月 11日 星期三 12:57:39 CST
table_help: 表引用命令提供帮助。
hbase(main):005:0* table_help
Help for table-reference commands.
You can either create a table via 'create' and then manipulate the table via commands like 'put', 'get', etc.
See the standard help information for how to use each of these commands.
However, as of 0.96, you can also get a reference to a table, on which you can invoke commands.
For instance, you can get create a table and keep around a reference to it via:
hbase> t = create 't', 'cf'
Or, if you have already created the table, you can get a reference to it:
hbase> t = get_table 't'
You can do things like call 'put' on the table:
hbase> t.put 'r', 'cf:q', 'v'
which puts a row 'r' with column family 'cf', qualifier 'q' and value 'v' into table t.
To read the data out, you can scan the table:
hbase> t.scan
which will read all the rows in table 't'.
Essentially, any command that takes a table name can also be done via table reference.
Other commands include things like: get, delete, deleteall,
get_all_columns, get_counter, count, incr. These functions, along with
the standard JRuby object methods are also available via tab completion.
For more information on how to use each of these commands, you can also just type:
hbase> t.help 'scan'
which will output more information on how to use that command.
You can also do general admin actions directly on a table; things like enable, disable,
flush and drop just by typing:
hbase> t.enable
hbase> t.flush
hbase> t.disable
hbase> t.drop
Note that after dropping a table, your reference to it becomes useless and further usage
is undefined (and not recommended).
whoami: 提供有关用户的信息。
hbase(main):006:0> whoami
root (auth:SIMPLE)
groups: root
Took 0.0402 seconds