3.3.2 修改表信息(alter命令)

alter命令用于修改表信息。

语法:

1)新增列族:


    alter  '表名','列族名称','列族名称'

2)修改列族可以存储的版本数量:


    alter '表名',{NAME=>'列族名称',VERSIONS=>版本号}

3)删除列族:


    alter '表名',{NAME=>'列族名称',METHOD=>'delete'}

4)修改Region大小:


    alter '表名',MAX_FILESIZE=>'字节数'

范例一:新增列族


    #创建表
hbase(main):005:0> create 'test1','info1'
Created table test1
Took 1.6391 seconds
=> HBase::Table - test1
#修改表
hbase(main):006:0> alter 'test1','info2','info3'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.1867 seconds
hbase(main):007:0>

命令解析:先使用create命令为表test1创建一个名为info1的列族,之后使用alter命令为表test1新增名为info2和info3的列族。

范例二:修改列族可存储的版本数量


    #创建表
hbase(main):001:0> create 'test2' ,{NAME=>'info1',VERSIONS=>1}
Created table test2
Took 1.5423 seconds
=> HBase::Table - test2
#修改表
hbase(main):002:0> alter 'test2',{NAME=>'info1',VERSIONS=>3}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.0341 seconds
#查看表信息
hbase(main):004:0> describe 'test2'
Table test2 is ENABLED
test2
COLUMN FAMILIES DESCRIPTION
{NAME => 'info1',
VERSIONS => '3',
EVICT_BLOCKS_ON_CLOSE => 'false',
NEW_VERSION_BEHAVIOR => 'false',
KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false',
DATA_BLOCK_ENCODING => 'NONE',
TTL => 'FOREVER',
MIN_VERSIONS => '0',
REPLICATION_SCOPE => '0',
BLOOMFILTER => 'ROW',
CACHE_INDEX_ON_WRITE => 'false',
IN_MEMORY => 'false',
CACHE_BLOOMS_ON_WRITE => 'false',
PREFETCH_BLOCKS_
ON_OPEN => 'false',
COMPRESSION => 'NONE',
BLOCKCACHE => 'true',
BLOCKSIZE => '65536'}
1 row(s)
Took 0.0587 seconds

命令解析:创建一个名为test2的表,表中名为info1的列族可存储的版本数量是1;使用alter命令把此列族可存储的版本数量修改为3;通过describe命令查询到当前info1列族可存储的版本数量是3。

范例三:删除列族


    #创建表
hbase(main):003:0> create 'test3', 'info1','info2'
Created table test3
Took 0.7327 seconds
=> HBase::Table - test3
#查看当前表信息
hbase(main):004:0> describe 'test3'
Table test3 is ENABLED
test3
COLUMN FAMILIES DESCRIPTION
{NAME => 'info1',
VERSIONS => '1',
EVICT_BLOCKS_ON_CLOSE => 'false',
NEW_VERSION_BEHAVIOR => 'false',
KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false',
DATA_BLOCK_ENCODING => 'NONE',
TTL => 'FOREVER',
MIN_VERSIONS => '0',
REPLICATION_SCOPE => '0',
BLOOMFILTER => 'ROW',
CACHE_INDEX_ON_WRITE => 'false',
IN_MEMORY => 'false',
CACHE_BLOOMS_ON_WRITE => 'false',
PREFETCH_BLOCKS_
ON_OPEN => 'false',
COMPRESSION => 'NONE',
BLOCKCACHE => 'true',
BLOCKSIZE => '65536'}
{NAME => 'info2',
VERSIONS => '1',
EVICT_BLOCKS_ON_CLOSE => 'false',
NEW_VERSION_BEHAVIOR => 'false',
KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false',
DATA_BLOCK_ENCODING => 'NONE',
TTL => 'FOREVER',
MIN_VERSIONS => '0',
REPLICATION_SCOPE => '0',
BLOOMFILTER => 'ROW',
CACHE_INDEX_ON_WRITE => 'false',
IN_MEMORY => 'false',
CACHE_BLOOMS_ON_WRITE => 'false',
PREFETCH_BLOCKS_ON_OPEN => 'false',
COMPRESSION => 'NONE',
BLOCKCACHE => 'true',
BLOCKSIZE => '65536'}
2 row(s)
Took 0.1123 seconds
#修改表
hbase(main):006:0> alter 'test3',{NAME=>'info1',METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.8120 seconds
#查看表修改之后的信息
hbase(main):007:0> describe 'test3'
Table test3 is ENABLED
test3
COLUMN FAMILIES DESCRIPTION
{NAME => 'info2',
VERSIONS => '1',
EVICT_BLOCKS_ON_CLOSE => 'false',
NEW_VERSION_BEHAVIOR => 'false',
KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false',
DATA_BLOCK_ENCODING => 'NONE'
, TTL => 'FOREVER', MIN_VERSIONS => '0',
REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW',
CACHE_INDEX_ON_WRITE => 'false',
IN_MEMORY => 'false',
CACHE_BLOOMS_ON_WRITE => 'false',
PREFETCH_BLOCKS_
ON_OPEN => 'false',
COMPRESSION => 'NONE',
BLOCKCACHE => 'true',
BLOCKSIZE => '65536'}
1 row(s)
Took 0.0333 seconds
hbase(main):008:0>

命令解析:使用alter命令把表test3之前的两个名为info1和info2的列族修改成只剩下一个名为info2的列族。

范例四:修改Region大小


    hbase(main):001:0> alter 'test3',MAX_FILESIZE=>'134217728'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.8394 seconds

命令解析:使用alter命令把Region大小修改为128MB。