You may have to modify properties of the existing table to add more column families or to modify the table attributes. HBase has ‘alter’ command’. In this article, we will check alter HBase table using shell command with some common examples to alter HBase table.
Alter HBase Table using shell command
This command alters the column family schema. You can use the HBase Alter shell command used to make changes to an existing table. Using this command, you can change the table properties or attributes such as set version, set and delete table scope operators, and delete a column family from an existing table.
HBase Alter Table Syntax
Below is the HBase alter table syntax:
alter <tablename>, NAME=>’<column familyname>’, VERSIONS=><new version no>
You can add or remove column from the HBase table. You can also modify the table properties.
HBase Alter Table Examples
Below are some of the common examples of HBase alter table command.
HBase Alter Table add column family
Let’s say you have created the table with column family name colFam1 and want to add one more column family. Below is the example:
hbase(main):005:0> alter 'test_table', {NAME=> 'colFam2'} Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.5210 seconds
HBase Alter Table drop column family
Below is the example to drop column family from HBase table:
hbase(main):011:0> alter 'test_table', {NAME => 'colFam2', METHOD => 'delete'} Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.7310 seconds
You can use the other method to delete column from HBase table
hbase(main):013:0> alter 'test_table', 'delete'=> 'colFam2' Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.4470 seconds
Alter HBase Table to add versions
Below is the example to add versions to existing table:
hbase(main):015:0> alter 'test_table', {NAME=> 'colFam1',VERSIONS => 2} Updating all regions with the new schema... 0/1 regions updated. 1/1 regions updated. Done. 0 row(s) in 3.2200 seconds
Alter HBase Table to add Time TO Live (TTL)
Below is the example to add Time TO Live (TTL) to existing table:
hbase(main):016:0> alter 'test_table', {NAME=> 'colFam1',TTL => 2000 } Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.2140 seconds
Alter HBase Table to enable snappy Compression
Below is the example to enable snappy compression on the existing HBase column family:
hbase(main):017:0> alter 'test_table', {NAME=> 'colFam1',COMPRESSION=>'snappy'} Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.2530 seconds
Before applying snappy compression you should first configure it.
Read:
- Drop HBase Tables using shell Commands and Examples
- Read HBase Table using HBase shell get Command
- Hadoop HDFS Architecture Introduction and Design
- Create Tables using HBase Shell
- Official Apache HBase documentation
- HBase Architecture and its Components
- Commonly used General Hbase Shell Commands