How to delete data in Table in HBase

Last updated on May 30 2022
Sonali Singh

Table of Contents

How to delete data in Table in HBase

HBase – Delete Data

Deleting a Specific Cell in a Table

Using the delete command, you can delete a specific cell in a table. The syntax of delete command is as follows:

delete ‘<table name>’, ‘<row>’, ‘<column name >’, ‘<time stamp>’

Example

Here is an example to delete a specific cell. Here we are deleting the salary.

hbase(main):006:0> delete ’emp’, ‘1’, ‘personal data:city’,

1417521848375

0 row(s) in 0.0060 seconds

Deleting All Cells in a Table

Using the “deleteall” command, you can delete all the cells in a row. Given below is the syntax of deleteall command.

deleteall ‘<table name>’, ‘<row>’,

Example

Here is an example of “deleteall” command, where we are deleting all the cells of row1 of emp table.

hbase(main):007:0> deleteall ’emp’,’1′

0 row(s) in 0.0240 seconds

Verify the table using the scan command. A snapshot of the table after deleting the table is given below.

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

 

ROW                  COLUMN + CELL

 

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

 

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

 

2 column = professional data:designation, timestamp = 1417524204, 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 = 1417523187, value = jr:engg

 

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

Deleting Data Using Java API

You can delete data from an HBase table using the delete() method of the HTable class. Follow the steps given below to delete data from a table.

Step 1: Instantiate the Configuration Class

Configuration class adds HBase configuration files to its object. You can create a configuration object using the create() method of the the HbaseConfiguration class as shown below.

Configuration conf = HbaseConfiguration.create();

Step 2: Instantiate the HTable Class

You have a class called HTable, an implementation of Table in HBase. This class is employed to communicate with a single HBase table. While instantiating this class, it accepts the configuration object and the table name as parameters. You can instantiate the HTable class as shown below.

HTable hTable = new HTable(conf, tableName);

Step 3: Instantiate the Delete Class

Instantiate the Delete class by passing the rowid of the row that is to be deleted, in byte array format. You can also pass timestamp and Rowlock to this constructor.

Delete delete = new Delete(toBytes(“row1”));

Step 4: Select the Data to be Deleted

You can delete the data using the delete methods of the Delete class. This class has various delete methods. Choose the columns or column families to be deleted using those methods. Take a look at the subsequent examples that show the usage of Delete class methods.

delete.deleteColumn(Bytes.toBytes(“personal”), Bytes.toBytes(“name”));

delete.deleteFamily(Bytes.toBytes(“professional”));

Step 5: Delete the Data

Delete the selected data by passing the delete instance to the delete() method of the HTable class as shown below.

table.delete(delete);

Step 6: Close the HTableInstance

After deleting the data, close the HTable Instance.

table.close();

Given below is the complete program to delete data from the HBase table.

import java.io.IOException;

 

import org.apache.hadoop.conf.Configuration;

 

import org.apache.hadoop.hbase.HBaseConfiguration;

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

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

import org.apache.hadoop.hbase.util.Bytes;

 

public class DeleteData {

 

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

 

// Instantiating Configuration class

Configuration conf = HBaseConfiguration.create();

 

// Instantiating HTable class

HTable table = new HTable(conf, “employee”);

 

// Instantiating Delete class

Delete delete = new Delete(Bytes.toBytes(“row1”));

delete.deleteColumn(Bytes.toBytes(“personal”), Bytes.toBytes(“name”));

delete.deleteFamily(Bytes.toBytes(“professional”));

 

// deleting the data

table.delete(delete);

 

// closing the HTable object

table.close();

System.out.println(“data deleted…..”);

}

}

Compile and execute the above program as shown below.

$javac Deletedata.java

$java DeleteData

The subsequent should be the output:

data deleted

 

So, this brings us to the end of blog. This Tecklearn ‘How to delete data in 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 delete data in Table in HBase"

Leave a Message

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