HBase - Enabling a Table


Enabling a Table using HBase Shell

Syntax to enable a table:

enable ‘emp’


Given below is an example to enable a table.

hbase(main):005:0> enable 'emp'
0 row(s) in 0.4580 seconds


After enabling the table, scan it. If you can see the schema, your table is successfully enabled.

hbase(main):006:0> scan 'emp'

   ROW                        COLUMN + CELL

1 column = personal data:city, timestamp = 1417516501, value = hyderabad

1 column = personal data:name, timestamp = 1417525058, value = ramu

1 column = professional data:designation, timestamp = 1417532601, value = manager

1 column = professional data:salary, timestamp = 1417524244109, value = 50000

2 column = personal data:city, timestamp = 1417524574905, value = chennai

2 column = personal data:name, timestamp = 1417524556125, value = ravi

2 column = professional data:designation, timestamp = 14175292204, value = sr:engg

2 column = professional data:salary, timestamp = 1417524604221, value = 30000 

3 column = personal data:city, timestamp = 1417524681780, value = delhi

3 column = personal data:name, timestamp = 1417524672067, value = rajesh

3 column = professional data:designation, timestamp = 14175246987, value = jr:engg

3 column = professional data:salary, timestamp = 1417524702514, value = 25000

3 row(s) in 0.0400 seconds


This command is used to find whether a table is enabled. Its syntax is as follows:

hbase> is_enabled 'table name'

The following code verifies whether the table named emp is enabled. If it is enabled, it will return true and if not, it will return false.

hbase(main):031:0> is_enabled 'emp'
0 row(s) in 0.0440 seconds

Enable a Table Using Java API

To verify whether a table is enabled, isTableEnabled() method is used; and to enable a table, enableTable() method is used. These methods belong to HBaseAdmin class. Follow the steps given below to enable a table.


Instantiate HBaseAdmin class as shown below.

// Creating configuration object
Configuration conf = HBaseConfiguration.create();

// Creating HBaseAdmin object
HBaseAdmin admin = new HBaseAdmin(conf);

Step 2

Verify whether the table is enabled using isTableEnabled() method as shown below.

Boolean bool = admin.isTableEnabled("emp");

Step 3

If the table is not disabled, disable it as shown below.

   System.out.println("Table enabled");

Given below is the complete program to verify whether the table is enabled and if it is not, then how to enable it.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class EnableTable{

   public static void main(String args[]) throws MasterNotRunningException, IOException{

      // Instantiating configuration class
      Configuration conf = HBaseConfiguration.create();

      // Instantiating HBaseAdmin class
      HBaseAdmin admin = new HBaseAdmin(conf);

      // Verifying weather the table is disabled
      Boolean bool = admin.isTableEnabled("emp");

      // Disabling the table using HBaseAdmin object
         System.out.println("Table Enabled");

Compile and execute the above program as shown below.

$javac EnableTable.java
$java EnableTable

The following should be the output:

Table Enabled