HBase Shell的应用案例

打印 上一主题 下一主题

主题 978|帖子 978|积分 2934

电商( eshop)平台具有海量数据、高并发访问、高速读写等特性,得当使用HBase分布式数据库进行数据存储。本节通过一个 HBase在电商平台的应用案例,熟练把握并综合运用HBase Shell命令行终端提供的各种操作命令。
一、电商(eshop)平台的逻辑数据模型

在HBase创建一个自定义命名空间eshop,用于存放电商平台的用户表shopping(客户商品订单表)。用户表shopping 包括customer、order和 item共三个列族,用逻辑数据模型来表示表中存放的数据。如表1所示:
表1 用逻辑数据模型表示电商系统用户表shopping中存放的数据
行键(RowKey)列族:customer列族:order列族:item
列限定符单元格值列限定符单元格值列限定符单元格值
s001nameJacknumber1item_nameiphone8
s001phone00000000001datetime2020-4-21price8000.00 
s001addressWuHanpay-statenot payed
s001levelnormal
s002nameTomnumber2item_nameHAWEI MATE X2
s002phone00000000002datetime2020-4-22price6000.00 
s002addressBeiJing
s002preferencee-product
s003nameMikenumber3item_nameXIAO MI 11
s003phone00000000003datetime2020-4-23price5000.00 
s003addressShangHai
s003age20
s004nameLucynumber4item_nameLancome
s004phone00000000004datetime2020-4-23price10000.00 
s004addressHangZhoupay-statepayed
s004preferencecosmeticspost-staterecieved
s004levelVIP
s005nameLilynumber10item_nameLV
s005phone00000000005datetime2020-4-23price20000.00 
s005preferencehandbagpay-statepayed
s005levelVIPpost-statedelivered
s005emailabc@qq.com
二、使用HBase Shell操作电商平台数据

1.对电商平台数据实行简朴读写操作

1)创建一个名称为eshop的名字空间,并列出HBase系统所有的名字空间。
  1. hbase:003:0> create_namespace 'eshop'
  2. Took 3.5909 seconds                                                                           
  3. hbase:004:0> list_namespace
  4. NAMESPACE                                                                                      
  5. default                                                                                       
  6. eshop                                                                                          
  7. hbase                                                                                          
  8. 3 row(s)
  9. Took 0.0606 seconds
复制代码
2)在eshop名字空间中创建表名为shopping的用户表,包罗1个列族customer;再列出HBase的所有数据表。
  1. hbase:012:0> create 'eshop:shopping','customer'
  2. 2024-03-22 01:33:35,528 INFO  [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: CREATE, Table Name: eshop:shopping, procId: 216 completed
  3. Created table eshop:shopping
  4. Took 2.5136 seconds                                                                           
  5. => Hbase::Table - eshop:shopping
  6. hbase:013:0> list
  7. TABLE                                                                                          
  8. eshop:shopping                                                                                 
  9. 1 row(s)
  10. Took 0.0670 seconds                                                                           
  11. => ["eshop:shopping"]
复制代码
3)给eshop 名字空间中的shopping表增加两个新的列族order和 item;再查看其表格结构。
  1. hbase:018:0> alter 'eshop:shopping','order','item'
  2. Updating all regions with the new schema...
  3. 1/1 regions updated.
  4. Done.
  5. Took 3.4106 seconds                                                                           
  6. hbase:019:0> desc 'eshop:shopping'
  7. Table eshop:shopping is ENABLED                                                               
  8. eshop:shopping, {TABLE_ATTRIBUTES => {METADATA => {'hbase.store.file-tracker.impl' => 'DEFAULT'
  9. }}}                                                                                            
  10. COLUMN FAMILIES DESCRIPTION                                                                    
  11. {NAME => 'customer', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FA
  12. LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE =
  13. > '0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true',
  14. BLOCKSIZE => '65536 B (64KB)'}                                                               
  15. {NAME => 'item', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE'
  16. , DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0
  17. ', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLO
  18. CKSIZE => '65536 B (64KB)'}                                                                    
  19. {NAME => 'order', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE
  20. ', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '
  21. 0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BL
  22. OCKSIZE => '65536 B (64KB)'}                                                                  
  23. 3 row(s)
复制代码
4)先删除 shopping表后再重新创建shopping表,包罗3个列族customer,order和 item。
  1. hbase:020:0> disable 'eshop:shopping'
  2. 2024-03-22 01:38:46,086 INFO  [main] client.HBaseAdmin (HBaseAdmin.java:rpcCall(926)) - Started disable of eshop:shopping
  3. 2024-03-22 01:38:46,764 INFO  [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: DISABLE, Table Name: eshop:shopping, procId: 228 completed
  4. Took 0.7314 seconds                                                                           
  5. hbase:021:0> drop 'eshop:shopping'
  6. 2024-03-22 01:38:58,599 INFO  [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: DELETE, Table Name: eshop:shopping, procId: 231 completed
  7. Took 0.4091 seconds                                                                           
  8. hbase:022:0> list
  9. TABLE                                                                                          
  10. 0 row(s)
  11. Took 0.0491 seconds                                                                           
  12. => []
  13. hbase:023:0> create 'eshop:shopping','customer','order','item'
  14. 2024-03-22 01:39:52,129 INFO  [main] client.HBaseAdmin (HBaseAdmin.java:postOperationResult(3591)) - Operation: CREATE, Table Name: eshop:shopping, procId: 232 completed
  15. Created table eshop:shopping
  16. Took 2.2332 seconds                                                                           
  17. => Hbase::Table - eshop:shopping
复制代码
5)修改shopping表的表级别属性,将文件巨细最大值修改为134217728字节。
  1. hbase:024:0> alter 'eshop:shopping',MAX_FILESIZE=>134217728
  2. Updating all regions with the new schema...
  3. 1/1 regions updated.
  4. Done.
  5. Took 2.2104 seconds
复制代码
6)描述shopping表的列族属性信息。
  1. hbase:025:0> desc 'eshop:shopping'
  2. Table eshop:shopping is ENABLED                                                               
  3. eshop:shopping, {TABLE_ATTRIBUTES => {MAX_FILESIZE => '134217728 B (128MB)', METADATA => {'hbas
  4. e.store.file-tracker.impl' => 'DEFAULT'}}}                                                     
  5. COLUMN FAMILIES DESCRIPTION                                                                    
  6. {NAME => 'customer', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FA
  7. LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE =
  8. > '0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true',
  9. BLOCKSIZE => '65536 B (64KB)'}                                                               
  10. {NAME => 'item', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE'
  11. , DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0
  12. ', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLO
  13. CKSIZE => '65536 B (64KB)'}                                                                    
  14. {NAME => 'order', INDEX_BLOCK_ENCODING => 'NONE', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE
  15. ', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '
  16. 0', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BL
  17. OCKSIZE => '65536 B (64KB)'}                                                                  
  18. 3 row(s)
  19. Quota is disabled
  20. Took 0.0846 seconds
复制代码
7)将用户表shopping逻辑数据模型中的所有数据写入到shooping表中。
  1. hbase:026:0> put 'eshop:shopping','s001','customer:name','Jack'
  2. Took 0.6497 seconds                                                                           
  3. hbase:027:0> put 'eshop:shopping','s001','customer:phone','00000000001'
  4. Took 0.0513 seconds                                                                           
  5. hbase:028:0> put 'eshop:shopping','s001','customer:address','WuHan'
  6. Took 0.0231 seconds                                                                           
  7. hbase:029:0> put 'eshop:shopping','s001','customer:level','normal'
  8. Took 0.0139 seconds                                                                           
  9. hbase:030:0> put 'eshop:shopping','s001','order:number','1'
  10. Took 0.0282 seconds                                                                           
  11. hbase:031:0> put 'eshop:shopping','s001','order:datetime','2020-4-21'
  12. Took 0.0488 seconds                                                                           
  13. hbase:032:0> put 'eshop:shopping','s001','order:pay-state','not-payed'
  14. Took 0.0215 seconds                                                                           
  15. hbase:033:0> put 'eshop:shopping','s001','item:item_name','iphone8'
  16. Took 0.0396 seconds                                                                           
  17. hbase:034:0> put 'eshop:shopping','s001','item:price','8000.00'
  18. Took 0.0133 seconds
  19. hbase:040:0> put 'eshop:shopping','s002','customer:name','Tom'
  20. Took 0.0170 seconds                                                                                                                    
  21. hbase:041:0> put 'eshop:shopping','s002','customer:phone','00000000002'
  22. Took 0.0196 seconds                                                                                                                    
  23. hbase:042:0> put 'eshop:shopping','s002','customer:address','BeiJing'
  24. Took 0.0214 seconds                                                                                                                    
  25. hbase:043:0> put 'eshop:shopping','s002','customer:preference','e-product'
  26. Took 0.0196 seconds                                                                                                                    
  27. hbase:044:0> put 'eshop:shopping','s002','order:number','2'
  28. Took 0.0150 seconds                                                                                                                    
  29. hbase:045:0> put 'eshop:shopping','s002','order:datetime','2020-4-22'
  30. Took 0.0149 seconds                                                                                                                    
  31. hbase:046:0> put 'eshop:shopping','s002','item:item_name','HUAWEI MATE X2'
  32. Took 0.0471 seconds                                                                                                                    
  33. hbase:047:0> put 'eshop:shopping','s002','item:price','6000.00'
  34. Took 0.0421 seconds
  35. hbase:053:0> put 'eshop:shopping','s003','customer:name','Mike'
  36. Took 0.0621 seconds                                                                                                                    
  37. hbase:054:0> put 'eshop:shopping','s003','customer:phone','00000000003'
  38. Took 0.0216 seconds                                                                                                                    
  39. hbase:055:0> put 'eshop:shopping','s003','customer:address','Shanghai'
  40. Took 0.0172 seconds                                                                                                                    
  41. hbase:056:0> put 'eshop:shopping','s003','customer:age','20'
  42. Took 0.0390 seconds                                                                                                                    
  43. hbase:057:0> put 'eshop:shopping','s003','order:number','3'
  44. Took 0.0605 seconds                                                                                                                    
  45. hbase:058:0> put 'eshop:shopping','s003','order:datetime','2020-4-23'
  46. Took 0.0120 seconds                                                                                                                    
  47. hbase:059:0> put 'eshop:shopping','s003','item:item_name','XIAO MI 11'
  48. Took 0.0084 seconds                                                                                                                    
  49. hbase:060:0> put 'eshop:shopping','s003','item:price','5000.00'
  50. Took 0.0207 seconds
  51. hbase:061:0> put 'eshop:shopping','s004','customer:name','Lucy'
  52. Took 0.0157 seconds                                                                                                                    
  53. hbase:062:0> put 'eshop:shopping','s004','customer:phone','00000000004'
  54. Took 0.0085 seconds                                                                                                                    
  55. hbase:063:0> put 'eshop:shopping','s004','customer:address','HangZhou'
  56. Took 0.0165 seconds                                                                                                                    
  57. hbase:064:0> put 'eshop:shopping','s004','customer:preference','cosmetics'
  58. Took 0.0166 seconds                                                                                                                    
  59. hbase:065:0> put 'eshop:shopping','s004','customer:level','VIP'
  60. Took 0.0113 seconds                                                                                                                    
  61. hbase:066:0> put 'eshop:shopping','s004','order:number','4'
  62. Took 0.0145 seconds                                                                                                                    
  63. hbase:067:0> put 'eshop:shopping','s004','order:datetime','202-4-23'
  64. Took 0.0300 seconds                                                                                                                    
  65. hbase:068:0> put 'eshop:shopping','s004','order:pay-state','payed'
  66. Took 0.0086 seconds                                                                                                                    
  67. hbase:069:0> put 'eshop:shopping','s004','order:post_state','recieved'
  68. Took 0.0148 seconds                                                                                                                    
  69. hbase:070:0> put 'eshop:shopping','s004','item:item_name','Lancome'
  70. Took 0.0251 seconds                                                                                                                    
  71. hbase:071:0> put 'eshop:shopping','s004','item:price','10000.00'
  72. Took 0.0289 seconds                                                                                                                    
  73. hbase:072:0> put 'eshop:shopping','s005','customer:name','Lily'
  74. Took 0.0249 seconds                                                                                                                    
  75. hbase:073:0> put 'eshop:shopping','s005','customer:phone','00000000005'
  76. Took 0.0286 seconds                                                                                                                    
  77. hbase:074:0> put 'eshop:shopping','s005','customer:preference','handbag'
  78. Took 0.0263 seconds                                                                                                                    
  79. hbase:075:0> put 'eshop:shopping','s005','customer:level','VIP'
  80. Took 0.0178 seconds                                                                                                                    
  81. hbase:076:0> put 'eshop:shopping','s005','customer:email','abc@qq.com'
  82. Took 0.0237 seconds                                                                                                                    
  83. hbase:077:0> put 'eshop:shopping','s005','order:number','10'
  84. Took 0.0098 seconds                                                                                                                    
  85. hbase:078:0> put 'eshop:shopping','s005','order:datetime','2020-4-23'
  86. Took 0.0211 seconds                                                                                                                    
  87. hbase:079:0> put 'eshop:shopping','s005','order:pay-state','payed'
  88. Took 0.0245 seconds                                                                                                                    
  89. hbase:080:0> put 'eshop:shopping','s005','order:post-state','delivered'
  90. Took 0.0256 seconds                                                                                                                    
  91. hbase:081:0> put 'eshop:shopping','s005','item:item_name','LV'
  92. Took 0.0258 seconds                                                                                                                    
  93. hbase:082:0> put 'eshop:shopping','s005','item:price','20000.00'
  94. Took 0.0199 seconds
复制代码
8)对shopping表进行全表扫描(读取所有数据行的所有数据列单元格)。
  1. hbase:084:0> scan 'eshop:shopping'
  2. ROW                                COLUMN+CELL                                                                                         
  3. s001                              column=customer:address, timestamp=2024-03-22T01:53:27.728, value=WuHan                             
  4. s001                              column=customer:level, timestamp=2024-03-22T01:54:02.171, value=normal                              
  5. s001                              column=customer:name, timestamp=2024-03-22T02:01:27.551, value=Jack                                 
  6. s001                              column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001                        
  7. s001                              column=item:item_name, timestamp=2024-03-22T01:57:17.558, value=iphone8                             
  8. s001                              column=item:price, timestamp=2024-03-22T01:57:36.270, value=8000.00                                 
  9. s001                              column=order:datetime, timestamp=2024-03-22T01:56:12.975, value=2020-4-21                           
  10. s001                              column=order:number, timestamp=2024-03-22T01:55:44.843, value=1                                    
  11. s001                              column=order:pay-state, timestamp=2024-03-22T01:56:41.609, value=not-payed                          
  12. s002                              column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing                           
  13. s002                              column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom                                 
  14. s002                              column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002                        
  15. s002                              column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product                     
  16. s002                              column=item:item_name, timestamp=2024-03-22T02:05:43.969, value=HUAWEI MATE X2                     
  17. s002                              column=item:price, timestamp=2024-03-22T02:06:41.294, value=6000.00                                 
  18. s002                              column=order:datetime, timestamp=2024-03-22T02:05:05.397, value=2020-4-22                           
  19. s002                              column=order:number, timestamp=2024-03-22T02:04:44.084, value=2                                    
  20. s003                              column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai                          
  21. s003                              column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20                                    
  22. s003                              column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike                                 
  23. s003                              column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003                        
  24. s003                              column=item:item_name, timestamp=2024-03-22T02:24:45.930, value=XIAO MI 11                          
  25. s003                              column=item:price, timestamp=2024-03-22T02:25:02.682, value=5000.00                                 
  26. s003                              column=order:datetime, timestamp=2024-03-22T02:24:17.560, value=2020-4-23                           
  27. s003                              column=order:number, timestamp=2024-03-22T02:24:00.754, value=3                                    
  28. s004                              column=customer:address, timestamp=2024-03-22T02:26:34.380, value=HangZhou                          
  29. s004                              column=customer:level, timestamp=2024-03-22T02:27:35.830, value=VIP                                 
  30. s004                              column=customer:name, timestamp=2024-03-22T02:25:44.580, value=Lucy                                 
  31. s004                              column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004                        
  32. s004                              column=customer:preference, timestamp=2024-03-22T02:27:17.408, value=cosmetics                     
  33. s004                              column=item:item_name, timestamp=2024-03-22T02:29:59.988, value=Lancome                             
  34. s004                              column=item:price, timestamp=2024-03-22T02:30:16.339, value=10000.00                                
  35. s004                              column=order:datetime, timestamp=2024-03-22T02:28:40.420, value=202-4-23                           
  36. s004                              column=order:number, timestamp=2024-03-22T02:28:20.236, value=4                                    
  37. s004                              column=order:pay-state, timestamp=2024-03-22T02:28:59.712, value=payed                              
  38. s004                              column=order:post_state, timestamp=2024-03-22T02:29:21.588, value=recieved                          
  39. s005                              column=customer:email, timestamp=2024-03-22T02:33:56.564, value=abc@qq.com                          
  40. s005                              column=customer:level, timestamp=2024-03-22T02:33:34.457, value=VIP                                 
  41. s005                              column=customer:name, timestamp=2024-03-22T02:31:36.776, value=Lily                                 
  42. s005                              column=customer:phone, timestamp=2024-03-22T02:32:24.128, value=00000000005                        
  43. s005                              column=customer:preference, timestamp=2024-03-22T02:33:09.550, value=handbag                        
  44. s005                              column=item:item_name, timestamp=2024-03-22T02:36:24.703, value=LV                                 
  45. s005                              column=item:price, timestamp=2024-03-22T02:36:40.468, value=20000.00                                
  46. s005                              column=order:datetime, timestamp=2024-03-22T02:34:45.746, value=2020-4-23                           
  47. s005                              column=order:number, timestamp=2024-03-22T02:34:23.380, value=10                                    
  48. s005                              column=order:pay-state, timestamp=2024-03-22T02:35:07.771, value=payed                              
  49. s005                              column=order:post-state, timestamp=2024-03-22T02:35:59.275, value=delivered                        
  50. 5 row(s)
  51. Took 0.1527 seconds
复制代码
9)读取shopping表的行键为s004的所有数据列的单元格值。
  1. hbase:085:0> get 'eshop:shopping','s004'
  2. COLUMN                             CELL                                                                                                
  3. customer:address                  timestamp=2024-03-22T02:26:34.380, value=HangZhou                                                   
  4. customer:level                    timestamp=2024-03-22T02:27:35.830, value=VIP                                                        
  5. customer:name                     timestamp=2024-03-22T02:25:44.580, value=Lucy                                                      
  6. customer:phone                    timestamp=2024-03-22T02:26:07.073, value=00000000004                                                
  7. customer:preference               timestamp=2024-03-22T02:27:17.408, value=cosmetics                                                  
  8. item:item_name                    timestamp=2024-03-22T02:29:59.988, value=Lancome                                                   
  9. item:price                        timestamp=2024-03-22T02:30:16.339, value=10000.00                                                   
  10. order:datetime                    timestamp=2024-03-22T02:28:40.420, value=202-4-23                                                   
  11. order:number                      timestamp=2024-03-22T02:28:20.236, value=4                                                         
  12. order:pay-state                   timestamp=2024-03-22T02:28:59.712, value=payed                                                      
  13. order:post_state                  timestamp=2024-03-22T02:29:21.588, value=recieved                                                   
  14. 1 row(s)
  15. Took 0.3746 seconds
复制代码
10)读取shopping表的行键s005,列族customer,列限定符preference 的数据列的单元格值。
  1. hbase:087:0> get 'eshop:shopping','s005','customer:preference'
  2. COLUMN                             CELL                                                                                             
  3. customer:preference               timestamp=2024-03-22T02:33:09.550, value=handbag                                                  
  4. 1 row(s)
  5. Took 0.0361 seconds
复制代码
2.对电商平台数据实行复杂读写操作

1)修改shopping表的列族属性,将列族order的列族属性VERSIONS修改为3。
  1. hbase:090:0> alter 'eshop:shopping',NAME=>'order',VERSIONS=>3
  2. Updating all regions with the new schema...
  3. 1/1 regions updated.
  4. Done.
  5. Took 6.8406 seconds
复制代码
2)修改shopping 表的列族属性,将列族order的列族属性TTL生存时间修改为1周,压缩模式修改为gz。
  1. hbase:093:0> alter 'eshop:shopping',NAME=>'info',TTL=>60*60*24*7,COMPRESSION=>'gz'
  2. Updating all regions with the new schema...
  3. 1/1 regions updated.
  4. Done.
  5. Took 3.3336 seconds
复制代码
3)将shopping表的行键为s001,列族为order,列限定符为number 的数据列的单元格值依次修改为2和3。
  1. hbase:094:0> put 'eshop:shopping','s001','order:number',2
  2. Took 0.0721 seconds                                                                                                                  
  3. hbase:095:0> put 'eshop:shopping','s001','order:number',3
  4. Took 0.0368 seconds
复制代码
4)读取shopping表客户Jack(行键为s001)的订单中商品数量的最近3次的版本值。
  1. hbase:096:0> get 'eshop:shopping','s001',{COLUMN=>'order:number',VERSIONS=>3}
  2. COLUMN                             CELL                                                                                             
  3. order:number                      timestamp=2024-03-22T02:54:22.959, value=3                                                        
  4. order:number                      timestamp=2024-03-22T02:54:19.466, value=2                                                        
  5. order:number                      timestamp=2024-03-22T01:55:44.843, value=1                                                        
  6. 1 row(s)
  7. Took 0.1118 seconds
复制代码
5)对shopping表指定行键范围s002到s004的数据行进行扫描,扫描效果包括第s002行,也包括第s004行。
  1. hbase:098:0> scan 'eshop:shopping',{STARTROW=>'s002',STOPROW=>'s005'}
  2. ROW                                COLUMN+CELL                                                                                       
  3. s002                              column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing                        
  4. s002                              column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom                                
  5. s002                              column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002                       
  6. s002                              column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product                    
  7. s002                              column=item:item_name, timestamp=2024-03-22T02:05:43.969, value=HUAWEI MATE X2                    
  8. s002                              column=item:price, timestamp=2024-03-22T02:06:41.294, value=6000.00                              
  9. s002                              column=order:datetime, timestamp=2024-03-22T02:05:05.397, value=2020-4-22                        
  10. s002                              column=order:number, timestamp=2024-03-22T02:04:44.084, value=2                                   
  11. s003                              column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai                        
  12. s003                              column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20                                 
  13. s003                              column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike                              
  14. s003                              column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003                       
  15. s003                              column=item:item_name, timestamp=2024-03-22T02:24:45.930, value=XIAO MI 11                        
  16. s003                              column=item:price, timestamp=2024-03-22T02:25:02.682, value=5000.00                              
  17. s003                              column=order:datetime, timestamp=2024-03-22T02:24:17.560, value=2020-4-23                        
  18. s003                              column=order:number, timestamp=2024-03-22T02:24:00.754, value=3                                   
  19. s004                              column=customer:address, timestamp=2024-03-22T02:26:34.380, value=HangZhou                        
  20. s004                              column=customer:level, timestamp=2024-03-22T02:27:35.830, value=VIP                              
  21. s004                              column=customer:name, timestamp=2024-03-22T02:25:44.580, value=Lucy                              
  22. s004                              column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004                       
  23. s004                              column=customer:preference, timestamp=2024-03-22T02:27:17.408, value=cosmetics                    
  24. s004                              column=item:item_name, timestamp=2024-03-22T02:29:59.988, value=Lancome                           
  25. s004                              column=item:price, timestamp=2024-03-22T02:30:16.339, value=10000.00                              
  26. s004                              column=order:datetime, timestamp=2024-03-22T02:28:40.420, value=202-4-23                          
  27. s004                              column=order:number, timestamp=2024-03-22T02:28:20.236, value=4                                   
  28. s004                              column=order:pay-state, timestamp=2024-03-22T02:28:59.712, value=payed                           
  29. s004                              column=order:post_state, timestamp=2024-03-22T02:29:21.588, value=recieved                        
  30. 3 row(s)
  31. Took 0.2564 seconds
复制代码
6)对shopping表的列族customer 中的所有数据列进行扫描。
  1. hbase:099:0> scan 'eshop:shopping',{COLUMNS=>'customer'}
  2. ROW                                COLUMN+CELL                                                                                       
  3. s001                              column=customer:address, timestamp=2024-03-22T01:53:27.728, value=WuHan                           
  4. s001                              column=customer:level, timestamp=2024-03-22T01:54:02.171, value=normal                           
  5. s001                              column=customer:name, timestamp=2024-03-22T02:01:27.551, value=Jack                              
  6. s001                              column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001                       
  7. s002                              column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing                        
  8. s002                              column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom                                
  9. s002                              column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002                       
  10. s002                              column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product                    
  11. s003                              column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai                        
  12. s003                              column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20                                 
  13. s003                              column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike                              
  14. s003                              column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003                       
  15. s004                              column=customer:address, timestamp=2024-03-22T02:26:34.380, value=HangZhou                        
  16. s004                              column=customer:level, timestamp=2024-03-22T02:27:35.830, value=VIP                              
  17. s004                              column=customer:name, timestamp=2024-03-22T02:25:44.580, value=Lucy                              
  18. s004                              column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004                       
  19. s004                              column=customer:preference, timestamp=2024-03-22T02:27:17.408, value=cosmetics                    
  20. s005                              column=customer:email, timestamp=2024-03-22T02:33:56.564, value=abc@qq.com                        
  21. s005                              column=customer:level, timestamp=2024-03-22T02:33:34.457, value=VIP                              
  22. s005                              column=customer:name, timestamp=2024-03-22T02:31:36.776, value=Lily                              
  23. s005                              column=customer:phone, timestamp=2024-03-22T02:32:24.128, value=00000000005                       
  24. s005                              column=customer:preference, timestamp=2024-03-22T02:33:09.550, value=handbag                     
  25. 5 row(s)
  26. Took 0.0883 seconds
复制代码
7)对shopping表的列族customer中列名为phone的所有数据列进行扫描。
  1. hbase:100:0> scan 'eshop:shopping',{COLUMNS=>'customer:phone'}
  2. ROW                                COLUMN+CELL                                                                                       
  3. s001                              column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001                       
  4. s002                              column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002                       
  5. s003                              column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003                       
  6. s004                              column=customer:phone, timestamp=2024-03-22T02:26:07.073, value=00000000004                       
  7. s005                              column=customer:phone, timestamp=2024-03-22T02:32:24.128, value=00000000005                       
  8. 5 row(s)
  9. Took 0.0275 seconds
复制代码
8)对shopping表的前3行数据进行扫描。
  1. hbase:101:0> scan 'eshop:shopping',{LIMIT=>3}
  2. ROW                                COLUMN+CELL                                                                                       
  3. s001                              column=customer:address, timestamp=2024-03-22T01:53:27.728, value=WuHan                           
  4. s001                              column=customer:level, timestamp=2024-03-22T01:54:02.171, value=normal                           
  5. s001                              column=customer:name, timestamp=2024-03-22T02:01:27.551, value=Jack                              
  6. s001                              column=customer:phone, timestamp=2024-03-22T01:52:48.474, value=00000000001                       
  7. s001                              column=item:item_name, timestamp=2024-03-22T01:57:17.558, value=iphone8                           
  8. s001                              column=item:price, timestamp=2024-03-22T01:57:36.270, value=8000.00                              
  9. s001                              column=order:datetime, timestamp=2024-03-22T01:56:12.975, value=2020-4-21                        
  10. s001                              column=order:number, timestamp=2024-03-22T02:54:22.959, value=3                                   
  11. s001                              column=order:pay-state, timestamp=2024-03-22T01:56:41.609, value=not-payed                        
  12. s002                              column=customer:address, timestamp=2024-03-22T02:03:43.489, value=BeiJing                        
  13. s002                              column=customer:name, timestamp=2024-03-22T02:02:58.983, value=Tom                                
  14. s002                              column=customer:phone, timestamp=2024-03-22T02:03:20.715, value=00000000002                       
  15. s002                              column=customer:preference, timestamp=2024-03-22T02:04:05.414, value=e-product                    
  16. s002                              column=item:item_name, timestamp=2024-03-22T02:05:43.969, value=HUAWEI MATE X2                    
  17. s002                              column=item:price, timestamp=2024-03-22T02:06:41.294, value=6000.00                              
  18. s002                              column=order:datetime, timestamp=2024-03-22T02:05:05.397, value=2020-4-22                        
  19. s002                              column=order:number, timestamp=2024-03-22T02:04:44.084, value=2                                   
  20. s003                              column=customer:address, timestamp=2024-03-22T02:23:25.999, value=Shanghai                        
  21. s003                              column=customer:age, timestamp=2024-03-22T02:23:39.768, value=20                                 
  22. s003                              column=customer:name, timestamp=2024-03-22T02:22:45.243, value=Mike                              
  23. s003                              column=customer:phone, timestamp=2024-03-22T02:23:08.255, value=00000000003                       
  24. s003                              column=item:item_name, timestamp=2024-03-22T02:24:45.930, value=XIAO MI 11                        
  25. s003                              column=item:price, timestamp=2024-03-22T02:25:02.682, value=5000.00                              
  26. s003                              column=order:datetime, timestamp=2024-03-22T02:24:17.560, value=2020-4-23                        
  27. s003                              column=order:number, timestamp=2024-03-22T02:24:00.754, value=3                                   
  28. 3 row(s)
  29. Took 0.1883 seconds
复制代码
9)统计shopping表中的数据行数。
  1. hbase:102:0> count 'eshop:shopping'
  2. 5 row(s)
  3. Took 0.1783 seconds                                                                                                                  
  4. => 5
复制代码
10)删除shopping表的行键为s005,列族为customer,列限定符为email的数据列。
  1. hbase:103:0> delete 'eshop:shopping','s005','customer:email'
  2. Took 0.1145 seconds
复制代码
3.对电商平台数据实行其他高级操作 

1)对shopping表的行键为s003,列族为item,列限定符为item_name的数据列单元格值追加内容Ultra。

  1. hbase:162:0> append 'eshop:shopping','s003','item:item_name','Ultra'
  2. CURRENT VALUE = XIAO MI 11Ultra
  3. Took 0.2864 seconds
复制代码
2)查看HBase集群状态(status)的具体信息,并查看HBase的当前软件版本(version)信息。
  1. hbase:163:0> status
  2. 1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
  3. Took 0.0503 seconds                                                                                              
  4. hbase:164:0> version
  5. 2.5.6, r6bac842797dc26bedb7adc0759358e4c8fd5a992, Sat Oct 14 23:36:46 PDT 2023
复制代码
 3)创建一个新的命名空间new_ns,并列出HBase当前所有的命名空间。
  1. hbase:165:0> create_namespace 'new_ns'
  2. Took 0.1475 seconds                                                                                              
  3. hbase:166:0> list_namespace
  4. NAMESPACE                                                                                                        
  5. default                                                                                                          
  6. eshop                                                                                                            
  7. hbase                                                                                                            
  8. new_ns                                                                                                            
  9. 4 row(s)
  10. Took 0.0316 seconds
复制代码
4)删除名称为new_ns的命名空间。
  1. hbase:167:0> drop_namespace 'new_ns'
  2. Took 0.1751 seconds
复制代码
5)给默认命名空间default增加一个属性名user,属性值为root。

  1. hbase:168:0> alter_namespace 'default',METHOD=>'set','user'=>'root'
  2. Took 0.1915 seconds
复制代码
6)描述命名空间default的属性信息。

  1. hbase:169:0> describe_namespace 'default'
  2. DESCRIPTION                                                                                                      
  3. {NAME => 'default', user => 'root'}                                                                              
  4. Quota is disabled
  5. Took 0.0151 seconds
复制代码
7)列出系统命名空间hbase中包罗的所有数据表。
  1. hbase:172:0> list_namespace_tables 'hbase'
  2. TABLE                                                                                                            
  3. meta                                                                                                              
  4. namespace                                                                                                        
  5. 2 row(s)
  6. Took 0.0349 seconds                                                                                              
  7. => ["meta", "namespace"]
复制代码
 


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

笑看天下无敌手

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表