1. 程式人生 > >HBase筆記之namespace

HBase筆記之namespace

進行 main rule value 創建 com links .com base

一、什麽是namespace

在RDBMS中有database的概念,用來對table進行分組,那麽在HBase中當表比較多的時候如何對表分組呢,就是namespace,可以簡單的把namespace理解為RDBMS中的database。

二、namespace相關操作

HBase有兩個內置的namespace:

hbase(main):009:0> list_namespace
NAMESPACE                                                                                                                                           
default                                                                                                                                             
hbase                                                                                                                                               
2 row(s)
Took 0.0683 seconds                                                                                                                            

hbase:用來存放系統相關的一些元數據等,相當於mysql中的mysql數據庫:

hbase(main):025:0> list_namespace_tables "hbase""
TABLE                                                                                                                                               
meta                                                                                                                                                
namespace                                                                                                                                           
2 row(s)
Took 0.0174 seconds                                                                                                                                 
=> ["meta", "namespace"]

default:創建表時未指定命名空間的話默認掛在default下。

創建namespace:

hbase(main):010:0> create_namespace "test"
Took 0.2781 seconds

在創建namespace的時候還可以添加一些說明信息:

hbase(main):018:0> create_namespace "test002", {"author"=>"CC11001100", "create_time"=>"2018-11-4 17:51:53"}
Took 0.2262 seconds    

上面創建namespace時添加了一些附加信息,如何查看這些附加信息呢:

hbase(main):019:0> describe_namespace "test002""
DESCRIPTION                                                                                                                                         
{NAME => ‘test002‘, author => ‘CC11001100‘, create_time => ‘2018-11-4 17:51:53‘}                                                                    
Took 0.0042 seconds                                                                                                                                 
=> 1

查看附加信息發現作者寫錯了,需要修改:

hbase(main):014:0> alter_namespace "test002", {METHOD=>"set", "author"=>"ChenEr"}
Took 0.2458 seconds                                                                                                                                 
hbase(main):015:0> describe_namespace "test002"
DESCRIPTION                                                                                                                                         
{NAME => ‘test002‘, author => ‘ChenEr‘, create_time => ‘2018-11-4 17:51:53‘}                                                                        
Took 0.0056 seconds                                                                                                                                 
=> 1

改完發現還漏了一項,需要追加自己的聯系方式:

hbase(main):016:0> alter_namespace "test002", {METHOD=>"set", "email"=>"[email protected]"}
Took 0.2313 seconds                                                                                                                                 
hbase(main):017:0> describe_namespace "test002"
DESCRIPTION                                                                                                                                         
{NAME => ‘test002‘, author => ‘ChenEr‘, create_time => ‘2018-11-4 17:51:53‘, email => ‘[email protected]‘}                                          
Took 0.0038 seconds                                                                                                                                 
=> 1

想了下放上去自己的聯系方式搞不好會被不斷騷擾,還是去掉此項屬性:

hbase(main):010:0> alter_namespace "test002", {METHOD=>"unset", NAME=>"email"}
Took 0.2419 seconds                                                                                                                                 
hbase(main):011:0> describe_namespace "test002"
DESCRIPTION                                                                                                                                         
{NAME => ‘test002‘, author => ‘ChenEr‘, create_time => ‘2018-11-4 17:51:53‘}                                                                        
Took 0.0056 seconds                                                                                                                                 
=> 1

總結:

添加或修改屬性:

alter_namespace ‘ns1‘, {METHOD => ‘set‘, ‘PROPERTY_NAME‘ => ‘PROPERTY_VALUE‘}

刪除屬性:

alter_namespace ‘ns1‘, {METHOD => ‘unset‘, NAME=>‘PROPERTY_NAME‘}

查看當前已經創建的namespace,相當於RDBMS中的show databases:

hbase(main):019:0> list_namespace
NAMESPACE                                                                                                                                           
default                                                                                                                                             
hbase                                                                                                                                               
test                                                                                                                                                
test002                                                                                                                                             
4 row(s)
Took 0.0122 seconds    

刪除namespace:

hbase(main):019:0> list_namespace
NAMESPACE                                                                                                                                           
default                                                                                                                                             
hbase                                                                                                                                               
test                                                                                                                                                
test002                                                                                                                                             
4 row(s)
Took 0.0122 seconds                                                                                                                                 
hbase(main):020:0> drop_namespace "test002"
Took 0.2321 seconds                                                                                                                                 
hbase(main):021:0> list_namespace
NAMESPACE                                                                                                                                           
default                                                                                                                                             
hbase                                                                                                                                               
test                                                                                                                                                
3 row(s)
Took 0.0111 seconds    

創建表時指定表所在的namespace,使用namespace-name:tale-name的格式指定:

hbase(main):022:0> create "test:user", "userInfo"
Created table test:user
Took 2.3992 seconds                                                                                                                                 
=> Hbase::Table - test:user

查看namespace下都有哪些表:

hbase(main):024:0> list_namespace_tables "test"
TABLE                                                                                                                                               
user                                                                                                                                                
1 row(s)
Took 0.0252 seconds                                                                                                                                 
=> ["user"]

.

HBase筆記之namespace