hbase 电商1

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'  # 合并
相关推荐
小鸡脚来咯4 小时前
Hive分桶表:大数据开发的性能优化利器
大数据·hive·性能优化
木卫二号Coding4 小时前
hivesql 字段aa值 如何去掉前面的0
hive
yumgpkpm1 天前
Cloudera CDP 7.3(国产CMP 鲲鹏版)平台与银行五大平台的技术对接方案
大数据·人工智能·hive·zookeeper·flink·kafka·cloudera
默 语3 天前
Spring Boot 3.x升级踩坑记:到底值不值得升级?
hive·spring boot·后端
ha_lydms3 天前
2、Spark 函数_a/b/c
大数据·c语言·hive·spark·时序数据库·dataworks·数据开发
本旺5 天前
【数据开发离谱场景记录】Hive + ES 复杂查询场景处理
hive·hadoop·elasticsearch
悟能不能悟6 天前
springboot全局异常
大数据·hive·spring boot
是阿威啊6 天前
【第六站】测试本地项目连接虚拟机上的大数据集群
大数据·linux·hive·hadoop·spark·yarn
青木川崎6 天前
hive实战
数据仓库·hive·hadoop