电商( eshop)平台具有海量数据、高并发访问、高速读写等特征,适合使用HBase分布式数据库进行数据存储。本节通过一个 HBase在电商平台的应用案例,熟练掌握并综合运用HBase Shell命令行终端提供的各种操作命令。
一、电商(eshop)平台的逻辑数据模型
在HBase创建一个自定义命名空间eshop,用于存放电商平台的用户表shopping(客户商品订单表)。用户表shopping 包括customer、order和 item共三个列族,用逻辑数据模型来表示表中存放的数据。如表1所示:
表1 用逻辑数据模型表示电商系统用户表shopping中存放的数据 | ||||||
行键(RowKey) | 列族:customer | 列族:order | 列族:item | |||
列限定符 | 单元格值 | 列限定符 | 单元格值 | 列限定符 | 单元格值 | |
s001 | name | Jack | number | 1 | item_name | iphone8 |
s001 | phone | 00000000001 | datetime | 2020-4-21 | price | 8000.00 |
s001 | address | WuHan | pay-state | not payed | ||
s001 | level | normal | ||||
s002 | name | Tom | number | 2 | item_name | HAWEI MATE X2 |
s002 | phone | 00000000002 | datetime | 2020-4-22 | price | 6000.00 |
s002 | address | BeiJing | ||||
s002 | preference | e-product | ||||
s003 | name | Mike | number | 3 | item_name | XIAO MI 11 |
s003 | phone | 00000000003 | datetime | 2020-4-23 | price | 5000.00 |
s003 | address | ShangHai | ||||
s003 | age | 20 | ||||
s004 | name | Lucy | number | 4 | item_name | Lancome |
s004 | phone | 00000000004 | datetime | 2020-4-23 | price | 10000.00 |
s004 | address | HangZhou | pay-state | payed | ||
s004 | preference | cosmetics | post-state | recieved | ||
s004 | level | VIP | ||||
s005 | name | Lily | number | 10 | item_name | LV |
s005 | phone | 00000000005 | datetime | 2020-4-23 | price | 20000.00 |
s005 | preference | handbag | pay-state | payed | ||
s005 | level | VIP | post-state | delivered | ||
s005 | email | abc@qq.com |
二、使用HBase Shell操作电商平台数据
1.对电商平台数据执行简单读写操作
1)创建一个名称为eshop的名字空间,并列出HBase系统所有的名字空间。
hbase:003:0> create_namespace 'eshop'
Took 3.5909 seconds
hbase:004:0> list_namespace
NAMESPACE
default
eshop
hbase
3 row(s)
Took 0.0606 seconds
2)在eshop名字空间中创建表名为shopping的用户表,包含1个列族customer;再列出HBase的所有数据表。
hbase:012:0> create 'eshop:shopping','customer'
2024-03-22 01:33:35,528 INFO [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: CREATE, Table Name: eshop:shopping, procId: 216 completed
Created table eshop:shopping
Took 2.5136 seconds
=> Hbase::Table - eshop:shopping
hbase:013:0> list
TABLE
eshop:shopping
1 row(s)
Took 0.0670 seconds
=> ["eshop:shopping"]
3)给eshop 名字空间中的shopping表增加两个新的列族order和 item;再查看其表格结构。
hbase:018:0> alter 'eshop:shopping','order','item'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 3.4106 seconds
hbase:019:0> desc 'eshop:shopping'
Table eshop:shopping is ENABLED
eshop:shopping, {TABLE_ATTRIBUTES => {METADATA => {'hbase.store.file-tracker.impl' => 'DEFAULT'
}}}
COLUMN FAMILIES DESCRIPTION
{NAME => 'customer', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE =
> '0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true',
BLOCKSIZE => '65536 B (64KB)'}
{NAME => 'item', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE'
, DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0
', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLO
CKSIZE => '65536 B (64KB)'}
{NAME => 'order', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE
', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '
0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BL
OCKSIZE => '65536 B (64KB)'}
3 row(s)
4)先删除 shopping表后再重新创建shopping表,包含3个列族customer,order和 item。
hbase:020:0> disable 'eshop:shopping'
2024-03-22 01:38:46,086 INFO [main] client.HBaseAdmin (HBaseAdmin.java:rpcCall(926)) - Started disable of eshop:shopping
2024-03-22 01:38:46,764 INFO [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: DISABLE, Table Name: eshop:shopping, procId: 228 completed
Took 0.7314 seconds
hbase:021:0> drop 'eshop:shopping'
2024-03-22 01:38:58,599 INFO [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: DELETE, Table Name: eshop:shopping, procId: 231 completed
Took 0.4091 seconds
hbase:022:0> list
TABLE
0 row(s)
Took 0.0491 seconds
=> []
hbase:023:0> create 'eshop:shopping','customer','order','item'
2024-03-22 01:39:52,129 INFO [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: CREATE, Table Name: eshop:shopping, procId: 232 completed
Created table eshop:shopping
Took 2.2332 seconds
=> Hbase::Table - eshop:shopping
5)修改shopping表的表级别属性,将文件大小最大值修改为134217728字节。
hbase:024:0> alter 'eshop:shopping',MAX_FILESIZE=>134217728
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.2104 seconds
6)描述shopping表的列族属性信息。
hbase:025:0> desc 'eshop:shopping'
Table eshop:shopping is ENABLED
eshop:shopping, {TABLE_ATTRIBUTES => {MAX_FILESIZE => '134217728 B (128MB)', METADATA => {'hbas
e.store.file-tracker.impl' => 'DEFAULT'}}}
COLUMN FAMILIES DESCRIPTION
{NAME => 'customer', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE =
> '0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true',
BLOCKSIZE => '65536 B (64KB)'}
{NAME => 'item', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE'
, DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0
', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLO
CKSIZE => '65536 B (64KB)'}
{NAME => 'order', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE
', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '
0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BL
OCKSIZE => '65536 B (64KB)'}
3 row(s)
Quota is disabled
Took 0.0846 seconds
7)将用户表shopping逻辑数据模型中的所有数据写入到shooping表中。
hbase:026:0> put 'eshop:shopping','s001','customer:name','Jack'
Took 0.6497 seconds
hbase:027:0> put 'eshop:shopping','s001','customer:phone','00000000001'
Took 0.0513 seconds
hbase:028:0> put 'eshop:shopping','s001','customer:address','WuHan'
Took 0.0231 seconds
hbase:029:0> put 'eshop:shopping','s001','customer:level','normal'
Took 0.0139 seconds
hbase:030:0> put 'eshop:shopping','s001','order:number','1'
Took 0.0282 seconds
hbase:031:0> put 'eshop:shopping','s001','order:datetime','2020-4-21'
Took 0.0488 seconds
hbase:032:0> put 'eshop:shopping','s001','order:pay-state','not-payed'
Took 0.0215 seconds
hbase:033:0> put 'eshop:shopping','s001','item:item_name','iphone8'
Took 0.0396 seconds
hbase:034:0> put 'eshop:shopping','s001','item:price','8000.00'
Took 0.0133 seconds
hbase:040:0> put 'eshop:shopping','s002','customer:name','Tom'
Took 0.0170 seconds
hbase:041:0> put 'eshop:shopping','s002','customer:phone','00000000002'
Took 0.0196 seconds
hbase:042:0> put 'eshop:shopping','s002','customer:address','BeiJing'
Took 0.0214 seconds
hbase:043:0> put 'eshop:shopping','s002','customer:preference','e-product'
Took 0.0196 seconds
hbase:044:0> put 'eshop:shopping','s002','order:number','2'
Took 0.0150 seconds
hbase:045:0> put 'eshop:shopping','s002','order:datetime','2020-4-22'
Took 0.0149 seconds
hbase:046:0> put 'eshop:shopping','s002','item:item_name','HUAWEI MATE X2'
Took 0.0471 seconds
hbase:047:0> put 'eshop:shopping','s002','item:price','6000.00'
Took 0.0421 seconds
hbase:053:0> put 'eshop:shopping','s003','customer:name','Mike'
Took 0.0621 seconds
hbase:054:0> put 'eshop:shopping','s003','customer:phone','00000000003'
Took 0.0216 seconds
hbase:055:0> put 'eshop:shopping','s003','customer:address','Shanghai'
Took 0.0172 seconds
hbase:056:0> put 'eshop:shopping','s003','customer:age','20'
Took 0.0390 seconds
hbase:057:0> put 'eshop:shopping','s003','order:number','3'
Took 0.0605 seconds
hbase:058:0> put 'eshop:shopping','s003','order:datetime','2020-4-23'
Took 0.0120 seconds
hbase:059:0> put 'eshop:shopping','s003','item:item_name','XIAO MI 11'
Took 0.0084 seconds
hbase:060:0> put 'eshop:shopping','s003','item:price','5000.00'
Took 0.0207 seconds
hbase:061:0> put 'eshop:shopping','s004','customer:name','Lucy'
Took 0.0157 seconds
hbase:062:0> put 'eshop:shopping','s004','customer:phone','00000000004'
Took 0.0085 seconds
hbase:063:0> put 'eshop:shopping','s004','customer:address','HangZhou'
Took 0.0165 seconds
hbase:064:0> put 'eshop:shopping','s004','customer:preference','cosmetics'
Took 0.0166 seconds
hbase:065:0> put 'eshop:shopping','s004','customer:level','VIP'
Took 0.0113 seconds
hbase:066:0> put 'eshop:shopping','s004','order:number','4'
Took 0.0145 seconds
hbase:067:0> put 'eshop:shopping','s004','order:datetime','202-4-23'
Took 0.0300 seconds
hbase:068:0> put 'eshop:shopping','s004','order:pay-state','payed'
Took 0.0086 seconds
hbase:069:0> put 'eshop:shopping','s004','order:post_state','recieved'
Took 0.0148 seconds
hbase:070:0> put 'eshop:shopping','s004','item:item_name','Lancome'
Took 0.0251 seconds
hbase:071:0> put 'eshop:shopping','s004','item:price','10000.00'
Took 0.0289 seconds
hbase:072:0> put 'eshop:shopping','s005','customer:name','Lily'
Took 0.0249 seconds
hbase:073:0> put 'eshop:shopping','s005','customer:phone','00000000005'
Took 0.0286 seconds
hbase:074:0> put 'eshop:shopping','s005','customer:preference','handbag'
Took 0.0263 seconds
hbase:075:0> put 'eshop:shopping','s005','customer:level','VIP'
Took 0.0178 seconds
hbase:076:0> put 'eshop:shopping','s005','customer:email','abc@qq.com'
Took 0.0237 seconds
hbase:077:0> put 'eshop:shopping','s005','order:number','10'
Took 0.0098 seconds
hbase:078:0> put 'eshop:shopping','s005','order:datetime','2020-4-23'
Took 0.0211 seconds
hbase:079:0> put 'eshop:shopping','s005','order:pay-state','payed'
Took 0.0245 seconds
hbase:080:0> put 'eshop:shopping','s005','order:post-state','delivered'
Took 0.0256 seconds
hbase:081:0> put 'eshop:shopping','s005','item:item_name','LV'
Took 0.0258 seconds
hbase:082:0> put 'eshop:shopping','s005','item:price','20000.00'
Took 0.0199 seconds
8)对shopping表进行全表扫描(读取所有数据行的所有数据列单元格)。
hbase:084:0> scan 'eshop:shopping'
ROW COLUMN+CELL
s001 column=customer:address, timestamp=2024-03-22T01:53:27.728, value=WuHan
s001 column=customer:level, timestamp=2024-03-22T01:54:02.171, value=normal
s001 column=customer:name, timestamp=2024-03-22T02:01:27.551, value=Jack
s001 column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001
s001 column=item:item_name, timestamp=2024-03-22T01:57:17.558, value=iphone8
s001 column=item:price, timestamp=2024-03-22T01:57:36.270, value=8000.00
s001 column=order:datetime, timestamp=2024-03-22T01:56:12.975, value=2020-4-21
s001 column=order:number, timestamp=2024-03-22T01:55:44.843, value=1
s001 column=order:pay-state, timestamp=2024-03-22T01:56:41.609, value=not-payed
s002 column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing
s002 column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom
s002 column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002
s002 column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product
s002 column=item:item_name, timestamp=2024-03-22T02:05:43.969, value=HUAWEI MATE X2
s002 column=item:price, timestamp=2024-03-22T02:06:41.294, value=6000.00
s002 column=order:datetime, timestamp=2024-03-22T02:05:05.397, value=2020-4-22
s002 column=order:number, timestamp=2024-03-22T02:04:44.084, value=2
s003 column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai
s003 column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20
s003 column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike
s003 column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003
s003 column=item:item_name, timestamp=2024-03-22T02:24:45.930, value=XIAO MI 11
s003 column=item:price, timestamp=2024-03-22T02:25:02.682, value=5000.00
s003 column=order:datetime, timestamp=2024-03-22T02:24:17.560, value=2020-4-23
s003 column=order:number, timestamp=2024-03-22T02:24:00.754, value=3
s004 column=customer:address, timestamp=2024-03-22T02:26:34.380, value=HangZhou
s004 column=customer:level, timestamp=2024-03-22T02:27:35.830, value=VIP
s004 column=customer:name, timestamp=2024-03-22T02:25:44.580, value=Lucy
s004 column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004
s004 column=customer:preference, timestamp=2024-03-22T02:27:17.408, value=cosmetics
s004 column=item:item_name, timestamp=2024-03-22T02:29:59.988, value=Lancome
s004 column=item:price, timestamp=2024-03-22T02:30:16.339, value=10000.00
s004 column=order:datetime, timestamp=2024-03-22T02:28:40.420, value=202-4-23
s004 column=order:number, timestamp=2024-03-22T02:28:20.236, value=4
s004 column=order:pay-state, timestamp=2024-03-22T02:28:59.712, value=payed
s004 column=order:post_state, timestamp=2024-03-22T02:29:21.588, value=recieved
s005 column=customer:email, timestamp=2024-03-22T02:33:56.564, value=abc@qq.com
s005 column=customer:level, timestamp=2024-03-22T02:33:34.457, value=VIP
s005 column=customer:name, timestamp=2024-03-22T02:31:36.776, value=Lily
s005 column=customer:phone, timestamp=2024-03-22T02:32:24.128, value=00000000005
s005 column=customer:preference, timestamp=2024-03-22T02:33:09.550, value=handbag
s005 column=item:item_name, timestamp=2024-03-22T02:36:24.703, value=LV
s005 column=item:price, timestamp=2024-03-22T02:36:40.468, value=20000.00
s005 column=order:datetime, timestamp=2024-03-22T02:34:45.746, value=2020-4-23
s005 column=order:number, timestamp=2024-03-22T02:34:23.380, value=10
s005 column=order:pay-state, timestamp=2024-03-22T02:35:07.771, value=payed
s005 column=order:post-state, timestamp=2024-03-22T02:35:59.275, value=delivered
5 row(s)
Took 0.1527 seconds
9)读取shopping表的行键为s004的所有数据列的单元格值。
hbase:085:0> get 'eshop:shopping','s004'
COLUMN CELL
customer:address timestamp=2024-03-22T02:26:34.380, value=HangZhou
customer:level timestamp=2024-03-22T02:27:35.830, value=VIP
customer:name timestamp=2024-03-22T02:25:44.580, value=Lucy
customer:phone timestamp=2024-03-22T02:26:07.073, value=00000000004
customer:preference timestamp=2024-03-22T02:27:17.408, value=cosmetics
item:item_name timestamp=2024-03-22T02:29:59.988, value=Lancome
item:price timestamp=2024-03-22T02:30:16.339, value=10000.00
order:datetime timestamp=2024-03-22T02:28:40.420, value=202-4-23
order:number timestamp=2024-03-22T02:28:20.236, value=4
order:pay-state timestamp=2024-03-22T02:28:59.712, value=payed
order:post_state timestamp=2024-03-22T02:29:21.588, value=recieved
1 row(s)
Took 0.3746 seconds
10)读取shopping表的行键s005,列族customer,列限定符preference 的数据列的单元格值。
hbase:087:0> get 'eshop:shopping','s005','customer:preference'
COLUMN CELL
customer:preference timestamp=2024-03-22T02:33:09.550, value=handbag
1 row(s)
Took 0.0361 seconds
2.对电商平台数据执行复杂读写操作
1)修改shopping表的列族属性,将列族order的列族属性VERSIONS修改为3。
hbase:090:0> alter 'eshop:shopping',NAME=>'order',VERSIONS=>3
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 6.8406 seconds
2)修改shopping 表的列族属性,将列族order的列族属性TTL生存时间修改为1周,压缩模式修改为gz。
hbase:093:0> alter 'eshop:shopping',NAME=>'info',TTL=>60*60*24*7,COMPRESSION=>'gz'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 3.3336 seconds
3)将shopping表的行键为s001,列族为order,列限定符为number 的数据列的单元格值依次修改为2和3。
hbase:094:0> put 'eshop:shopping','s001','order:number',2
Took 0.0721 seconds
hbase:095:0> put 'eshop:shopping','s001','order:number',3
Took 0.0368 seconds
4)读取shopping表客户Jack(行键为s001)的订单中商品数量的最近3次的版本值。
hbase:096:0> get 'eshop:shopping','s001',{COLUMN=>'order:number',VERSIONS=>3}
COLUMN CELL
order:number timestamp=2024-03-22T02:54:22.959, value=3
order:number timestamp=2024-03-22T02:54:19.466, value=2
order:number timestamp=2024-03-22T01:55:44.843, value=1
1 row(s)
Took 0.1118 seconds
5)对shopping表指定行键范围s002到s004的数据行进行扫描,扫描结果包括第s002行,也包括第s004行。
hbase:098:0> scan 'eshop:shopping',{STARTROW=>'s002',STOPROW=>'s005'}
ROW COLUMN+CELL
s002 column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing
s002 column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom
s002 column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002
s002 column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product
s002 column=item:item_name, timestamp=2024-03-22T02:05:43.969, value=HUAWEI MATE X2
s002 column=item:price, timestamp=2024-03-22T02:06:41.294, value=6000.00
s002 column=order:datetime, timestamp=2024-03-22T02:05:05.397, value=2020-4-22
s002 column=order:number, timestamp=2024-03-22T02:04:44.084, value=2
s003 column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai
s003 column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20
s003 column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike
s003 column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003
s003 column=item:item_name, timestamp=2024-03-22T02:24:45.930, value=XIAO MI 11
s003 column=item:price, timestamp=2024-03-22T02:25:02.682, value=5000.00
s003 column=order:datetime, timestamp=2024-03-22T02:24:17.560, value=2020-4-23
s003 column=order:number, timestamp=2024-03-22T02:24:00.754, value=3
s004 column=customer:address, timestamp=2024-03-22T02:26:34.380, value=HangZhou
s004 column=customer:level, timestamp=2024-03-22T02:27:35.830, value=VIP
s004 column=customer:name, timestamp=2024-03-22T02:25:44.580, value=Lucy
s004 column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004
s004 column=customer:preference, timestamp=2024-03-22T02:27:17.408, value=cosmetics
s004 column=item:item_name, timestamp=2024-03-22T02:29:59.988, value=Lancome
s004 column=item:price, timestamp=2024-03-22T02:30:16.339, value=10000.00
s004 column=order:datetime, timestamp=2024-03-22T02:28:40.420, value=202-4-23
s004 column=order:number, timestamp=2024-03-22T02:28:20.236, value=4
s004 column=order:pay-state, timestamp=2024-03-22T02:28:59.712, value=payed
s004 column=order:post_state, timestamp=2024-03-22T02:29:21.588, value=recieved
3 row(s)
Took 0.2564 seconds
6)对shopping表的列族customer 中的所有数据列进行扫描。
hbase:099:0> scan 'eshop:shopping',{COLUMNS=>'customer'}
ROW COLUMN+CELL
s001 column=customer:address, timestamp=2024-03-22T01:53:27.728, value=WuHan
s001 column=customer:level, timestamp=2024-03-22T01:54:02.171, value=normal
s001 column=customer:name, timestamp=2024-03-22T02:01:27.551, value=Jack
s001 column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001
s002 column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing
s002 column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom
s002 column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002
s002 column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product
s003 column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai
s003 column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20
s003 column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike
s003 column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003
s004 column=customer:address, timestamp=2024-03-22T02:26:34.380, value=HangZhou
s004 column=customer:level, timestamp=2024-03-22T02:27:35.830, value=VIP
s004 column=customer:name, timestamp=2024-03-22T02:25:44.580, value=Lucy
s004 column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004
s004 column=customer:preference, timestamp=2024-03-22T02:27:17.408, value=cosmetics
s005 column=customer:email, timestamp=2024-03-22T02:33:56.564, value=abc@qq.com
s005 column=customer:level, timestamp=2024-03-22T02:33:34.457, value=VIP
s005 column=customer:name, timestamp=2024-03-22T02:31:36.776, value=Lily
s005 column=customer:phone, timestamp=2024-03-22T02:32:24.128, value=00000000005
s005 column=customer:preference, timestamp=2024-03-22T02:33:09.550, value=handbag
5 row(s)
Took 0.0883 seconds
7)对shopping表的列族customer中列名为phone的所有数据列进行扫描。
hbase:100:0> scan 'eshop:shopping',{COLUMNS=>'customer:phone'}
ROW COLUMN+CELL
s001 column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001
s002 column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002
s003 column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003
s004 column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004
s005 column=customer:phone, timestamp=2024-03-22T02:32:24.128, value=00000000005
5 row(s)
Took 0.0275 seconds
8)对shopping表的前3行数据进行扫描。
hbase:101:0> scan 'eshop:shopping',{LIMIT=>3}
ROW COLUMN+CELL
s001 column=customer:address, timestamp=2024-03-22T01:53:27.728, value=WuHan
s001 column=customer:level, timestamp=2024-03-22T01:54:02.171, value=normal
s001 column=customer:name, timestamp=2024-03-22T02:01:27.551, value=Jack
s001 column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001
s001 column=item:item_name, timestamp=2024-03-22T01:57:17.558, value=iphone8
s001 column=item:price, timestamp=2024-03-22T01:57:36.270, value=8000.00
s001 column=order:datetime, timestamp=2024-03-22T01:56:12.975, value=2020-4-21
s001 column=order:number, timestamp=2024-03-22T02:54:22.959, value=3
s001 column=order:pay-state, timestamp=2024-03-22T01:56:41.609, value=not-payed
s002 column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing
s002 column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom
s002 column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002
s002 column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product
s002 column=item:item_name, timestamp=2024-03-22T02:05:43.969, value=HUAWEI MATE X2
s002 column=item:price, timestamp=2024-03-22T02:06:41.294, value=6000.00
s002 column=order:datetime, timestamp=2024-03-22T02:05:05.397, value=2020-4-22
s002 column=order:number, timestamp=2024-03-22T02:04:44.084, value=2
s003 column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai
s003 column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20
s003 column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike
s003 column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003
s003 column=item:item_name, timestamp=2024-03-22T02:24:45.930, value=XIAO MI 11
s003 column=item:price, timestamp=2024-03-22T02:25:02.682, value=5000.00
s003 column=order:datetime, timestamp=2024-03-22T02:24:17.560, value=2020-4-23
s003 column=order:number, timestamp=2024-03-22T02:24:00.754, value=3
3 row(s)
Took 0.1883 seconds
9)统计shopping表中的数据行数。
hbase:102:0> count 'eshop:shopping'
5 row(s)
Took 0.1783 seconds
=> 5
10)删除shopping表的行键为s005,列族为customer,列限定符为email的数据列。
hbase:103:0> delete 'eshop:shopping','s005','customer:email'
Took 0.1145 seconds
3.对电商平台数据执行其他高级操作
1)对shopping表的行键为s003,列族为item,列限定符为item_name的数据列单元格值追加内容Ultra。
hbase:162:0> append 'eshop:shopping','s003','item:item_name','Ultra'
CURRENT VALUE = XIAO MI 11Ultra
Took 0.2864 seconds
2)查看HBase集群状态(status)的详细信息,并查看HBase的当前软件版本(version)信息。
hbase:163:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
Took 0.0503 seconds
hbase:164:0> version
2.5.6, r6bac842797dc26bedb7adc0759358e4c8fd5a992, Sat Oct 14 23:36:46 PDT 2023
3)创建一个新的命名空间new_ns,并列出HBase当前所有的命名空间。
hbase:165:0> create_namespace 'new_ns'
Took 0.1475 seconds
hbase:166:0> list_namespace
NAMESPACE
default
eshop
hbase
new_ns
4 row(s)
Took 0.0316 seconds
4)删除名称为new_ns的命名空间。
hbase:167:0> drop_namespace 'new_ns'
Took 0.1751 seconds
5)给默认命名空间default增加一个属性名user,属性值为root。
hbase:168:0> alter_namespace 'default',METHOD=>'set','user'=>'root'
Took 0.1915 seconds
6)描述命名空间default的属性信息。
hbase:169:0> describe_namespace 'default'
DESCRIPTION
{NAME => 'default', user => 'root'}
Quota is disabled
Took 0.0151 seconds
7)列出系统命名空间hbase中包含的所有数据表。
hbase:172:0> list_namespace_tables 'hbase'
TABLE
meta
namespace
2 row(s)
Took 0.0349 seconds
=> ["meta", "namespace"]