Enable a Table

Enabling a Table using HBase Shell

Syntax

enable ‘table_name’ 

E.g

hbase> enable 'emp'
0 row(s) in 0.5810 seconds

Verification

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

hbase> scan 'emp'

   ROW                        COLUMN + CELL
1 column = personal data:city, timestamp = 1417516501, value = bhimavaram
1 column = personal data:name, timestamp = 1417525058, value = ashok
1 column = professional data:designation, timestamp = 1417532601, value = software engineer
1 column = professional data:salary, timestamp = 1417524244109, value = 30000
2 column = personal data:city, timestamp = 1417524574905, value = chennai
2 column = personal data:name, timestamp = 1417524556125, value = vinod
2 column = professional data:designation, timestamp = 14175292204, value = cloud consultant
2 column = professional data:salary, timestamp = 1417524604221, value = 70000 
2 row(s) in 0.0400 seconds
is_enabled

This command is used to find whether a table is enabled.

Syntax

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> is_enabled 'emp'
true
0 row(s) in 0.0520 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.

package com.ashok.hbase;

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;

/**
 * 
 * @author ashok.mariyala
 *
 */
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");
      System.out.println(bool);

      // Disabling the table using HBaseAdmin object
      if(!bool){
         admin.enableTable("emp");
         System.out.println("Table Enabled");
      }
   }
}
Enable a Table
Scroll to top