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-client-project-2.4.16.jar是一个用于连接HBase数据库的Java客户端项目。HBase是一个分布式、面向的NoSQL数据库,它可以存储大规模数据,并提供高可靠性和高性能的数据访问。而hbase-client-project-2.4.16.jar则是用来连接HBase数据库的Java客户端库。通过这个库,开发人员可以在Java应用中方便地访问HBase数据库,进行数据的读取、写入和管理操作。 hbase-client-project-2.4.16.jar库提供了丰富的API,使得开发人员可以编写简洁、高效的代码来操作HBase数据库。通过这个库,可以轻松地建立与HBase集群的连接,创建、删除格,进行数据的增删改查等操作。此外,hbase-client-project-2.4.16.jar也提供了一些高级特性,比如支持过滤器、批量操作、数据版本控制等功能,让开发人员能够更加灵活地利用HBase数据库进行数据处理。 除此之外,hbase-client-project-2.4.16.jar还支持与HBase的安全认证和权限控制,可以保障数据访问的安全性。开发人员可以使用这个库来编写安全的Java应用,确保对HBase数据库的数据进行合法、受控的访问。 总之,hbase-client-project-2.4.16.jar是一个强大、灵活的Java客户端库,为开发人员提供了便捷的方式来连接、操作HBase数据库。无论是小规模的应用还是大规模的数据处理需求,它都能够满足开发人员的要求,帮助他们更有效地利用HBase数据库。 (字数: 258)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值