Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
There can be various operations on a table in HBase. We may need commands to create a table, describe a table, alter a table, display the list of tables present in HBase, enable and disable the table, and many more. Each of these operations has different commands. This article will discuss various such commands. We shall see the syntax, meaning, and example of each command.
Creating a table
Creating a table in HBase is as easy as creating a table in SQL. However, in the case of columns, we have column families in HBase, which in turn can have various qualifiers or attributes. It is also not necessary that each row will have the same column family qualifiers or attributes.
We did not specify any qualifiers like player name, staff name, etc.
We did not specify the row key.
There are no data types.
HBase is case-sensitive. Therefore 'table' is not the same as 'Table.'
Listing a table
The list command is used to display the list of all the tables present in the HBase. So this can also be used to verify if the table is created or not.
Syntax: list
The syntax for listing the tables is very simple. We just need to use the word list.
Example:
hbase (main) :003:0> list
Disabling a table
disable
The table needs to be disabled first if we want to change its settings or delete the table.
Syntax: disable 'table_name'
Example:
hbase(main):025:0> disable 'mytable'
The above command will disable the table named mytable.
is_disabled
In order to ascertain whether a given table is disabled or not, we can use the is_disabled command.
Syntax: is_disabled 'table_name'
Example:
hbase(main):030:0> is_disabled 'mytable'
It will display true if the table is disabled and false otherwise.
disable_all
This command is used to disable all such tables that match the given regex.
Syntax: disable_all 'regex'
Example:
hbase(main):004:01> disable_all 'a*'
The above code will disable all the tables starting with the letter a.
Enabling a table
enable
The enable command is used to enable a table that has been disabled earlier.
Syntax: enable ‘table_name’
Example:
hbase(main):005:0> enable 'mytable'
The above code will enable the "mytable" table again, which was disabled.
is_enabled
This command functions similarly to is_disabled. The is_enabled command is used to ascertain whether the given table is enabled or not. It returns true if it is enabled; otherwise, it returns false.
Syntax: is_enabled 'table_name'
Example:
hbase(main):041:0> is_enabled 'mytable'
Describe
The describe command is used to get the description of the table. The descriptions include version, compression, blocksize, etc. Apart from the description, it also returns whether the table is enabled or disabled.
Syntax: describe ‘table_name’
Example:
hbase(main):008:0> describe 'mytable'
Alter
The alter command is one of the most important commands of HBase. It is used to change or modify the attributes of an existing table. Suppose we want to add a new column family or delete an attribute from the column family. We can do this using the alter command.
Example:
hbase(main):005:0> alter 'mytable', {NAME=> 'columnfamily2'}
The above code will add another column family having the name columnfamily2.
Example:
hbase(main):006:0> alter 'mytable', {NAME => 'columnfamily2', METHOD => 'delete'}
The above code will delete the column family columnfamily2.
We can do various other operations on the table using the alter command like adding versions, etc.
Existence of a table
The exists command is used to check whether the table exists in the database or not. It returns true if the table exists; otherwise, it will return false.
Syntax: exits ‘table_name’
Example:
hbase(main):008:0> exists 'mytable'
Dropping a table
The drop command is used to delete the table permanently. However, it is necessary to first disable the table before we drop it. After dropping the table, we can use the exists command to check whether the table exists or not. If the table is deleted successfully, the exists command will return false.
Syntax: drop ‘table_name’
Example:
hbase(main):010:0> disable 'mytable'
hbase(main):011:0> drop 'mytable'
FAQs
Name some table management commands in HBase. create, list, disable, enable, describe, alter, exists, and drop.
Which command is used to create a table in Hbase? create
Which command displays all the tables in HBase? list
What is the difference between enable and disable commands in HBase? disable command is used to disable the table, which is required in case we want to change the settings of the table or delete the table. The enable command enables the already disabled table.