hbase基本操作---修改表的列簇

说实话,不管是hbase shell ,还是java api 我都没找到修改表的列簇的合适的方法。

hbase shell ,我只找到了,删除列簇,和添加一个列簇的方式
java API,我找到的也是删除列簇和添加一个列簇的方法,尽管有modifyColumnFamily这个方法,但是感觉并没有什么用。
比如我们现在有如下图一张表,我们需要修改列簇info为basic,并添加一个列簇super

希望各位有知道的不吝指教

hbase(main):001:0> scan 'zhangshk:tb8'
ROW                        COLUMN+CELL                                                                 
 10001                     column=info:age, timestamp=1513332853463, value=18                          
 10001                     column=info:name, timestamp=1513332853485, value=leo                        
 10001                     column=info:sex, timestamp=1513332853492, value=male                        
 10002                     column=info:name, timestamp=1513332853522, value=jack                       
 10003                     column=info:name, timestamp=1513332853539, value=tom                        
3 row(s) in 0.2540 seconds

hbase的ddl里面有一个alter方法,这个应该就是用来修改表定义的。

hbase(main):004:0> alter

Here is some help for this command:
Alter a table. If the *"hbase.online.schema.update.enable"* property is set to
false, then the table must be disabled (see help 'disable'). If the 
"hbase.online.schema.update.enable" property is set to true, tables can be 
altered without disabling them first. Altering enabled tables has caused problems 
in the past, so use caution and test it before using in production. 

You can use the alter command to add, 
modify or delete column families or change table configuration options.
Column families work in a similar way as the 'create' command. The column family
specification can either be a name string, or a dictionary with the NAME attribute.
Dictionaries are described in the output of the 'help' command, with no arguments.

For example, to change or add the 'f1' column family in table 't1' from 
current value to keep a maximum of 5 cell VERSIONS, do:

  hbase> alter 't1', NAME => 'f1', VERSIONS => 5

You can operate on several column families:

  hbase> alter 't1', 'f1', {NAME => 'f2', IN_MEMORY => true}, {NAME => 'f3', VERSIONS => 5}

To delete the 'f1' column family in table 'ns1:t1', use one of:

  hbase> alter 'ns1:t1', NAME => 'f1', METHOD => 'delete'
  hbase> alter 'ns1:t1', 'delete' => 'f1'

You can also change table-scope attributes like MAX_FILESIZE, READONLY, 
MEMSTORE_FLUSHSIZE, DURABILITY, etc. These can be put at the end;
for example, to change the max size of a region to 128MB, do:

  hbase> alter 't1', MAX_FILESIZE => '134217728'

You can add a table coprocessor by setting a table coprocessor attribute:

  hbase> alter 't1',
    'coprocessor'=>'hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2'

Since you can have multiple coprocessors configured for a table, a
sequence number will be automatically appended to the attribute name
to uniquely identify it.

The coprocessor attribute must match the pattern below in order for
the framework to understand how to load the coprocessor classes:

  [coprocessor jar file location] | class name | [priority] | [arguments]

You can also set configuration settings specific to this table or column family:

  hbase> alter 't1', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}
  hbase> alter 't1', {NAME => 'f2', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}

You can also remove a table-scope attribute:

  hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'MAX_FILESIZE'

  hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'coprocessor$1'

You can also set REGION_REPLICATION:

  hbase> alter 't1', {REGION_REPLICATION => 2}

There could be more than one alteration in one command:

  hbase> alter 't1', { NAME => 'f1', VERSIONS => 3 }, 
   { MAX_FILESIZE => '134217728' }, { METHOD => 'delete', NAME => 'f2' },
   OWNER => 'johndoe', METADATA => { 'mykey' => 'myvalue' }

如果hbase.online.schema.update.enable设置为true ,则不用先对表执行disable操作,如果hbase.online.schema.update.enable设置为false,需要先对表设置disable操作。
这里可以做的

添加列簇:

hbase(main):002:0> disable 'zhangshk:tb1'


hbase(main):044:0> alter 'zhangshk:tb1',NAME=>'infosss'
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.1250 seconds

hbase(main):045:0> describe 'zhangshk:tb1'
Table zhangshk:tb1 is ENABLED                                                                          
zhangshk:tb1                                                                                           
COLUMN FAMILIES DESCRIPTION                                                                            
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOC
KCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                      
{NAME => 'infoss', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => '
FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                    
{NAME => 'infosss', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 
'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', B
LOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                   
3 row(s) in 0.0220 seconds

hbase(main):039:0> describe 'zhangshk:tb1'
Table zhangshk:tb1 is ENABLED                                                                          
zhangshk:tb1                                                                                           
COLUMN FAMILIES DESCRIPTION                                                                            
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOC
KCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                      
{NAME => 'infosss', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 
'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', B
LOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                   
2 row(s) in 0.0220 seconds

删除列簇

hbase(main):040:0> alter 'zhangshk:tb1',NAME=>'infosss','METHOD'=>'delete'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.2640 seconds

hbase(main):041:0> describe 'zhangshk:tb1'
Table zhangshk:tb1 is ENABLED                                                                          
zhangshk:tb1                                                                                           
COLUMN FAMILIES DESCRIPTION                                                                            
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOC
KCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                      
1 row(s) in 0.0220 seconds

java API:

/**
     * 修改列簇
     * @param hBaseAdmin
     * @param tablename
     * @throws Exception
     */
    public static void modifyColumnFamily(HBaseAdmin hBaseAdmin,String tablename)throws Exception{
        hBaseAdmin.disableTable(tablename);
        hBaseAdmin.addColumn(tablename,new HColumnDescriptor("infos"));
        hBaseAdmin.modifyColumn(tablename,new HColumnDescriptor("infos"));
        hBaseAdmin.deleteColumn(tablename,"infos");
        hBaseAdmin.enableTable(tablename);
    }

你可能感兴趣的:(hbase存储系统)