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'  # 合并
相关推荐
姜穆澜15 小时前
Apache Hive 4.x 完全学习指南
大数据·hive
Gl�ria5 天前
Hive SQL 执行卡住完整排查 & 处理
hive·hadoop·sql
网络豆7 天前
Apache Hive 鸿蒙 PC 适配全记录:以 Qt 客户端打通 HiveQL、监控与元数据访问
hive·apache·harmonyos
fastjson_8 天前
Hive3.1.3 安装使用
hive
Gl�ria12 天前
Hadoop MapReduce/Hive 数据倾斜完整排查
hive·hadoop·mapreduce
Gl�ria12 天前
Hadoop Hive 和 YARN 的关系
数据仓库·hive·hadoop
fastjson_16 天前
Hive 自定义函数
数据仓库·hive·hadoop
Gent_倪16 天前
MySQL 与 Hive 语法异同点详解
数据库·hive·mysql
邀星月为媒19 天前
从零打造一个属于自己的 AI Agent:Core Hive Agent 开源项目解析
人工智能·hive·开源
BI专家之路19 天前
安装linux/hadoop/jdk/hive
linux·hive·hadoop