How to verify the existence of a Table and How to Drop a Table in HBase

Last updated on May 30 2022
Sonali Singh

Table of Contents

How to verify the existence of a Table and How to Drop a Table in HBase

HBase – Exists

Existence of Table using HBase Shell

You’ll verify the existence of a table using the exists command. The subsequent example shows how to use this command.

hbase(main):024:0> exists ’emp’

Table emp does exist

 

0 row(s) in 0.0750 seconds

 

==================================================================

 

hbase(main):015:0> exists ‘student’

Table student does not exist

 

0 row(s) in 0.0480 seconds

Verifying the Existence of Table Using Java API

You’ll verify the existence of a table in HBase using the tableExists() method of the HBaseAdmin class. Follow the steps given below to verify the existence of a table in HBase.

Step 1

Instantiate the HBaseAdimn class

 

// Instantiating configuration object

Configuration conf = HBaseConfiguration.create();

 

// Instantiating HBaseAdmin class

HBaseAdmin admin = new HBaseAdmin(conf);

Step 2

Verify the existence of the table using the tableExists( ) method.

Given below is the java program to test the existence of a table in HBase using java API.

import java.io.IOException;

 

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.conf.Configuration;

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

 

public class TableExists{

 

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

 

// Instantiating configuration class

Configuration conf = HBaseConfiguration.create();

 

// Instantiating HBaseAdmin class

HBaseAdmin admin = new HBaseAdmin(conf);

 

// Verifying the existance of the table

boolean bool = admin.tableExists(“emp”);

System.out.println( bool);

}

}

Compile and execute the above program as shown below.

$javac TableExists.java

$java TableExists

The subsequent should be the output:

true

 

 

HBase – Drop a Table

Dropping a Table using HBase Shell

Using the drop command, you’ll delete a table. Before dropping a table, you have to disable it.

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

0 row(s) in 1.4580 seconds

 

hbase(main):019:0> drop ’emp’

0 row(s) in 0.3060 seconds

Verify whether the table is deleted using the exists command.

hbase(main):020:07gt; exists ’emp’

Table emp does not exist

0 row(s) in 0.0730 seconds

drop_all

This command is employed to drop the tables matching the “regex” given in the command. Its syntax is as follows:

hbase> drop_all ‘t.*’

Note: Before dropping a table, you must disable it.

Example

Assume there are tables named raja, rajani, rajendra, rajesh, and raju.

hbase(main):017:0> list

TABLE

raja

rajani

rajendra

rajesh

raju

9 row(s) in 0.0270 seconds

All these tables start with the letters raj. First of all, let us disable all these tables using the disable_all command as shown below.

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

raja

rajani

rajendra

rajesh

raju

Disable the above 5 tables (y/n)?

y

5 tables successfully disabled

Now you’ll delete all of them using the drop_all command as given below.

hbase(main):018:0> drop_all ‘raj.*’

raja

rajani

rajendra

rajesh

raju

Drop the above 5 tables (y/n)?

y

5 tables successfully dropped

Deleting a Table Using Java API

You’ll delete a table using the deleteTable() method in the HBaseAdmin class. Follow the steps given below to delete a table using java API.

Step 1

Instantiate the HBaseAdmin class.

// creating a configuration object

Configuration conf = HBaseConfiguration.create();

 

// Creating HBaseAdmin object

HBaseAdmin admin = new HBaseAdmin(conf);

Step 2

Disable the table using the disableTable() method of the HBaseAdmin class.

admin.disableTable(“emp1”);

Step 3

Now delete the table using the deleteTable() method of the HBaseAdmin class.

admin.deleteTable(“emp12”);

Given below is the complete java program to delete a table in HBase.

import java.io.IOException;

 

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.conf.Configuration;

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

 

public class DeleteTable {

 

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

 

// Instantiating configuration class

Configuration conf = HBaseConfiguration.create();

 

// Instantiating HBaseAdmin class

HBaseAdmin admin = new HBaseAdmin(conf);

 

// disabling table named emp

admin.disableTable(“emp12”);

 

// Deleting emp

admin.deleteTable(“emp12”);

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

}

}

Compile and execute the above program as shown below.

$javac DeleteTable.java

$java DeleteTable

The subsequent should be the output:

Table deleted

 

So, this brings us to the end of blog. This Tecklearn ‘How to verify the existence of a Table and How to Drop a Table in HBase’ 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 verify the existence of a Table and How to Drop a Table in HBase"

Leave a Message

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