• Hbase 使用方法


    列出所有 table

    hbase(main):>	list
    

    新增 table

    A . 直接增加一個表 t2

    hbase(main):>	create 't2'
    

    B . 增加一個擁有 'f1','f2','fn' 為 column family 的表: t1

    hbase(main):>	create 't1','f1','f2','fn'   
    

    查詢 Table 欄位

    hbase(main):> describe 't1'
    

    執行結果參考

    hbase(main):> describe 't1'
    DESCRIPTION                                                             ENABLED                               
     {NAME => 't1', FAMILIES => [{NAME => 'f1', COMPRESSION => 'NONE', VERS true                                  
     IONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => '                                       
     false', BLOCKCACHE => 'true'}, {NAME => 'f2', COMPRESSION => 'NONE', V                                       
     ERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY =                                       
     > 'false', BLOCKCACHE => 'true'}, {NAME => 'fn', COMPRESSION => 'NONE'                                       
     , VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMOR                                       
     Y => 'false', BLOCKCACHE => 'true'}]} 
    

    加入cell-value

    需先擁有表 t1 與column-family : f1 並且加入一個 column-quantifier c1

    hbase(main):>	put 't1', 'r1', 'f1', 'v1'    
    hbase(main):>	put 't1', 'r1', 'f1:c1', 'v2'    
    hbase(main):>	put 't1', 'r2', 'f2', 'v3'
    hbase(main):>	put 't1', 'r2', 'f2:c2', 'v4'
    
    Table: 't1'
    row-key 'f1' 'f2' 'fn' column-family
    * 'c1' * 'c2' * column-quantifier
    r1 v1        
      v2      
    r2     v3    
          v4  

    列出cell-value

    A . 列出一列(row)

    hbase(main):>	get 't1', 'r1'
    

    執行結果參考

    COLUMN                    CELL                
     f1:                         timestamp=1285737082689, value=v1                                                
     f1:c1                       timestamp=1285737085874, value=v2                                          
    
    Table: 't1'
    row-key 'f1' 'f2' 'fn' column-family
    * 'c1' * 'c2' * column-quantifier
    r1 v1        
      v2      
    r2     v3    
          v4  

    B . 列出一個 cell 的值

    hbase(main):>   get 't1', 'r1', {COLUMN => 'f1:c1'}
    

    執行結果參考

    COLUMN                       CELL                             
     f1:c1                       timestamp=1285737085874, value=v2
    
    Table: 't1'
    row-key 'f1' 'f2' 'fn' column-family
    * 'c1' * 'c2' * column-quantifier
    r1 v1        
      v2      
    r2     v3    
          v4  

    刪除 cell-value

    hbase(main):>	deleteall 't1','r1'
    

    執行結果:會把 row-key 是 'r1' 的所有紀錄。此時資料表 't1' 會變成如下表所示。

    hbase(main):> scan 't1'                 
    ROW    COLUMN+CELL                                                                      
     r2    column=f2:, timestamp=1285737091644, value=v3                                    
     r2    column=f2:c2, timestamp=1285737094157, value=v4
    
    Table: 't1'
    row-key 'f1' 'f2' 'fn' column-family
    * 'c1' * 'c2' * column-quantifier
               
    r2     v3    
          v4  

    加入column family

    hbase(main):>	disable 't1'
    hbase(main):>   alter 't1', {NAME => 'f3'}
    hbase(main):>   enable 't1'
    

    執行結果:多了一個 column-family 'f3' 可以用 describe 指令查詢,結果示意如下表:

    hbase(main):021:0> describe 't1'
    DESCRIPTION                                                             ENABLED                               
     {NAME => 't1', FAMILIES => [{NAME => 'f1', COMPRESSION => 'NONE', VERS true                                  
     IONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => '                                       
     false', BLOCKCACHE => 'true'}, {NAME => 'f2', COMPRESSION => 'NONE', V                                       
     ERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY =                                       
     > 'false', BLOCKCACHE => 'true'}, {NAME => 'f3', VERSIONS => '3', COMP                                       
     RESSION => 'NONE', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMOR                                       
     Y => 'false', BLOCKCACHE => 'true'}, {NAME => 'fn', COMPRESSION => 'NO                                       
     NE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_ME                                       
     MORY => 'false', BLOCKCACHE => 'true'}]}
    
    Table: 't1'
    row-key 'f1' 'f2' 'f3' 'fn' column-family
    * 'c1' * 'c2' * * column-quantifier
    r2     v3      
          v4    

    刪除column family

    hbase(main):>	disable 't1'
    hbase(main):>	alter 't1', {NAME => 'f1', METHOD => 'delete'}
    hbase(main):>   enable 't1'
    

    執行結果:會移除 column family 為 'f1' 的所有欄位,可用 describe 指令確認,結果如下表所示。

    hbase(main):053:0> describe 't1'
    DESCRIPTION                                                             ENABLED                               
     {NAME => 't1', FAMILIES => [{NAME => 'f2', COMPRESSION => 'NONE', VERS true                                  
     IONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => '                                       
     false', BLOCKCACHE => 'true'}, {NAME => 'f3', COMPRESSION => 'NONE', V                                       
     ERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY =                                       
     > 'false', BLOCKCACHE => 'true'}, {NAME => 'fn', COMPRESSION => 'NONE'                                       
     , VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMOR                                       
     Y => 'false', BLOCKCACHE => 'true'}]}                                                                        
    1 row(s) in 0.0200 seconds
    
    Table: 't1'
    row-key   'f2' 'f3' 'fn' column-family
      * 'c2' * * column-quantifier
    r2   v3      
        v4    

    節點狀態

    hbase(main):>	status
    

    刪除整張table

    hbase(main):>	truncate 't1'
    
    • 執行完 truncate 後,所有 't1' 的內容都會被移除。但此時,下 list 還會有 't1' 這個表格存在。
    hbase(main):>	disable 't1'
    hbase(main):>	drop 't1'
    
    • 要完整移除 't1' 資料表,必須使用 disable 先將 't1' 停用,再用 drop 指令把 't1' 完全刪除。

    转自:http://trac.nchc.org.tw/cloud/wiki/NCHCCloudCourse100929_2_USE

  • 相关阅读:
    转--Android中自定义字体的实现方法
    android中Intent传值与Bundle传值的区别详解
    通过Application传递数据代码
    LayoutInflater的使用
    转--Android资源总结(环境搭建/ 反编译工具)
    转--android Toast大全(五种情形)建立属于你自己的Toast
    转--9中对话框
    转--全局异常处理
    安卓记住密码
    转--Android学习笔记-实用代码合集
  • 原文地址:https://www.cnblogs.com/xd502djj/p/3401078.html
Copyright © 2020-2023  润新知