1. 简单读写操作
(1) 创建 & 列出命名空间
shell
create_namespace 'eshop'
list_namespace
(2) 创建表 & 列出表
shell
create 'eshop:shopping', 'customer'
list
(3) 增加列族
shell
alter 'eshop:shopping', 'order', 'item'
(4) 删除 & 重建表
shell
disable 'eshop:shopping'
is_disabled 'eshop:shopping'
drop 'eshop:shopping'
create 'eshop:shopping', 'customer', 'order', 'item'
(5) 修改表文件大小属性
shell
alter 'eshop:shopping', {MAX_FILESIZE => 134217728}
(6) 描述表
shell
desc 'eshop:shopping'
(7) 写入数据(示例)
shell
put 'eshop:shopping', '0000000001-Jack', 'customer:name', 'Jack'
put 'eshop:shopping', '0000000001-Jack', 'customer:phone', ''
put 'eshop:shopping', '0000000001-Jack', 'customer:address', 'Wu Han'
put 'eshop:shopping', '0000000001-Jack', 'customer:level', 'normal'
# (其他put命令同理,如Lily的数据)
put 'eshop:shopping', '0000000005-Lily', 'order:post-state', 'delivered'
put 'eshop:shopping', '0000000005-Lily', 'customer:email', 'abce@qq.com'
(8) 全表扫描
shell
scan 'eshop:shopping'
(9) 读取指定行键
shell
get 'eshop:shopping', '0000000004-Lucy'
(10) 读取指定列
shell
get 'eshop:shopping', '0000000005-Lily', 'customer:preference'
2. 复杂读写操作
(1) 修改列族版本
shell
alter 'eshop:shopping', {NAME => 'order', VERSIONS => 3}
(2) 修改列族 TTL & 压缩(原文示例表名是 students,实际对应 shopping)
shell
alter 'students', {NAME => 'info', TTL => 60 * 60 * 24 * 7, COMPRESSION => 'gz'}
(3) 修改单元格值
shell
put 'eshop:shopping', '0000000001-Jack', 'order:number', 2
put 'eshop:shopping', '0000000001-Jack', 'order:number', 3
(4) 读取最近 3 次版本
shell
get 'eshop:shopping', '0000000001-Jack', {COLUMN => 'order:number', VERSIONS => 3}
(5) 范围扫描
shell
scan 'eshop:shopping', {STARTROW => '0000000002-Tom', STOPROW => '0000000005-Lily'}
(6) 扫描指定列族
shell
scan 'eshop:shopping', {COLUMNS => 'customer'}
(7) 扫描指定列限定符
shell
scan 'eshop:shopping', {COLUMNS => 'customer:phone'}
(8) 扫描前 3 行
shell
scan 'eshop:shopping', {LIMIT => 3}
(9) 统计表行数
shell
count 'eshop:shopping'
(10) 删除指定单元格
shell
delete 'eshop:shopping', '0000000005-Lily', 'customer:email'
3. 高级操作
(1) 追加单元格值
shell
append 'eshop:shopping', '0000000003-Mike', 'item:item_name', 'Ultra'
(2) 查看集群状态 & 版本
shell
status 'detailed'
version
(3) 创建 & 列出新命名空间
shell
create_namespace 'new_ns'
list_namespace
(4) 删除命名空间
shell
drop_namespace 'new_ns'
(5) 修改默认命名空间属性
shell
alter_namespace 'default', {METHOD => 'set', 'user' => 'root'}
(6) 描述默认命名空间
shell
describe_namespace 'default'
(7) 列出 hbase 命名空间的表
shell
list_namespace_tables 'hbase'
(8) 创建快照
shell
snapshot 'eshop:shopping', 'snapshot_eshop_shopping'
(9) 查看所有快照
shell
list_snapshots
(10) 克隆快照为新表
shell
clone_snapshot 'snapshot_eshop_shopping', 'eshop:shopping_clone'
4. 带过滤器的读操作
(1) 清空表 & 恢复快照
shell
truncate 'eshop:shopping' # 清数据
scan 'eshop:shopping' # 确认清除
disable 'eshop:shopping' # 禁用表
restore_snapshot 'snapshot_eshop_shopping' # 恢复快照
enable 'eshop:shopping' # 启用表
scan 'eshop:shopping' # 确认恢复
(2) ValueFilter 过滤(值 = Wu Han)
shell
scan 'eshop:shopping', {FILTER => "ValueFilter(=, 'binary:Wu Han')"}
(3) QualifierFilter 过滤(列名包含 re)
shell
scan 'eshop:shopping', {FILTER => "QualifierFilter(=, 'substring:re')"}
(4) ColumnPrefixFilter 过滤(列名前缀 = date)
shell
scan 'eshop:shopping', {FILTER => "ColumnPrefixFilter('date')"}
(5) RowFilter 过滤(行键包含 - L)
shell
scan 'eshop:shopping', {FILTER => "RowFilter(=, 'substring:-L')"}
(6) PrefixFilter 过滤(行键前缀 = 0000000001)
shell
scan 'eshop:shopping', {FILTER => "PrefixFilter('0000000001')"}
(7) FamilyFilter 过滤(列族名包含 er)
shell
scan 'eshop:shopping', {FILTER => "FamilyFilter(=, 'substring:er')"}
(8) SingleColumnValueFilter 过滤(客户爱好包含 c)
shell
scan 'eshop:shopping', {FILTER => "SingleColumnValueFilter('customer', 'preference', =, 'substring:c')"}
(9) 拆分 Region & 查看拆分结果
shell
split 'eshop:shopping', '0000000003-Mike'
get_splits 'eshop:shopping'
(10) 合并 Region
shell
scan 'hbase:meta' # 查询元数据获取Region编码(ENCODED_REGIONNAME1/2)
merge_region 'ENCODED_REGIONNAME1', 'ENCODED_REGIONNAME2' # 合并