How to enable and disable a Table using HBase shell

Last updated on May 30 2022
Sonali Singh

Table of Contents

How to enable and disable a Table using HBase shell

HBase – Disabling a Table

Disabling a Table using HBase Shell

To delete a table or change its settings, you need to first disable the table using the disable command. You can re-enable it using the enable command.

Given below is the syntax to disable a table:

disable ‘emp’

Example

Given below is an example that shows how to disable a table.

hbase(main):025:0> disable ’emp’

0 row(s) in 1.2760 seconds

Verification

After disabling the table, you can still sense its existence through list and exists commands. You cannot scan it. It will give you the subsequent error.

hbase(main):028:0> scan ’emp’

ROW         COLUMN + CELL

ERROR: emp is disabled.

is_disabled

This command is employed to find whether a table is disabled. Its syntax is as follows.

hbase> is_disabled ‘table name’

The subsequent example verifies whether the table named emp is disabled. If it is disabled, it will return true and if not, it will return false.

hbase(main):031:0> is_disabled ’emp’

true

0 row(s) in 0.0440 seconds

disable_all

This command is employed to disable all the tables matching the given regex. The syntax for disable_all command is given below.

hbase> disable_all ‘r.*’

Suppose there are 5 tables in HBase, namely raja, rajani, rajendra, rajesh, and raju. The subsequent code will disable all the tables starting with raj.

hbase(main):002:07> disable_all ‘raj.*’

raja

rajani

rajendra

rajesh

raju

Disable the above 5 tables (y/n)?

y

5 tables successfully disabled

Disable a Table Using Java API

To verify whether a table is disabled, isTableDisabled() method is employed and to disable a table, disableTable() method is employed. These methods belong to the HBaseAdmin class. Follow the steps given below to disable a table.

Step 1

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 disabled using isTableDisabled() method as shown below.

Boolean b = admin.isTableDisabled(“emp”);

Step 3

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

if(!b){

admin.disableTable(“emp”);

System.out.println(“Table disabled”);

}

Given below is the complete program to verify whether the table is disabled; if not, how to disable 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 DisableTable{

 

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.isTableDisabled(“emp”);

System.out.println(bool);

 

// Disabling the table using HBaseAdmin object

if(!bool){

admin.disableTable(“emp”);

System.out.println(“Table disabled”);

}

}

}

Compile and execute the above program as shown below.

$javac DisableTable.java

$java DsiableTable

The subsequent should be the output:

false

Table disabled

HBase – Enabling a Table

Enabling a Table using HBase Shell

Syntax to enable a table:

enable ‘emp’

Example

Given below is an example to enable a table.

hbase(main):005:0> enable ’emp’

0 row(s) in 0.4580 seconds

Verification

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

is_enabled

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

hbase> is_enabled ‘table name’

The subsequent 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’

true

0 row(s) in 0.0440 seconds

Enable a Table Using Java API

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

Step1

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.

if(!bool){

admin.enableTable(“emp”);

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 whether the table is disabled

Boolean bool = admin.isTableEnabled(“emp”);

System.out.println(bool);

 

// Enabling the table using HBaseAdmin object

if(!bool){

admin.enableTable(“emp”);

System.out.println(“Table Enabled”);

}

}

}

Compile and execute the above program as shown below.

$javac EnableTable.java

$java EnableTable

The subsequent should be the output:

false

Table Enabled

 

So, this brings us to the end of blog. This Tecklearn ‘How to enable and disable a Table using HBase shell’ helps you with commonly asked questions if you are looking out for a job in HBase and No-SQL Database Domain.

If you wish to learn HBase and build a career in HBase or No-SQL Database domain, then check out our interactive, Apache HBase Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/apache-hbase-training/

Apache HBase Training

About the Course

Tecklearn Apache HBase training will master the powerful NoSQL distributed database. You will learn HBase architecture, data analytics using HBase, integration with Hive, monitoring cluster using ZooKeeper and working on real-life industry projects. Build your career as a certified HBase professional through our hands-on training with real-world examples. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Apache HBase.

Why Should you take Apache HBase Training?

  • HBase is now the largest data-driven service serving top websites including Facebook Messaging Platform.
  • There is Strong demand for HBase qualified professionals and they are paid big bucks for the right skills.
  • According to indeed.com, the average pay of an HBase developer stands at $81,422 per annum.

What you will Learn in this Course?

Introduction to HBase and NoSQL

  • Introduction to HBase
  • Fundamentals of HBase
  • What is NoSQL
  • NoSQL Vs RDBMS
  • Why HBase
  • Where to use HBase

HBase Data Modelling

  • Data Modelling
  • HDFS vs. HBase
  • HBase Use Cases

HBase Architecture and Components

  • HBase Architecture
  • Components of HBase Cluster

HBase Installation

  • Prerequisites for HBase Installation
  • Installation Steps

Programming in HBase

  • Create an Eclipse Project for HBase
  • Simple Table Creation from Java in HBase
  • HBase API
  • HBase Shell
  • Primary operations and advanced operations

Integration of Hive with HBase

  • Create a table and insert data into it
  • Integration of Hive with HBase
  • HBase Mapping

Deep Dive into HBase

  • Input Data into HBase
  • File Loading
  • HDFS File
  • HBase handling files in File System
  • WAL
  • Seek Vs Transfer
  • HBase ACID Properties

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "How to enable and disable a Table using HBase shell"

Leave a Message

Your email address will not be published. Required fields are marked *