How to update data in Table using HBase Shell

Last updated on May 30 2022
Sonali Singh

Table of Contents

How to update data in Table using HBase Shell

HBase – Update Data

Updating Data using HBase Shell

You can update an existing cell value using the put command. To do so, just follow the same syntax and mention your new value as shown below.

put ‘table name’,’row ’,’Column family:column name’,’new value’

The newly given value replaces the existing value, updating the row.

Example

Suppose there is a table in HBase called emp with the subsequent data.

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

ROW              COLUMN + CELL

row1 column = personal:name, timestamp = 1418051555, value = raju

row1 column = personal:city, timestamp = 1418275907, value = Hyderabad

row1 column = professional:designation, timestamp = 14180555,value = manager

row1 column = professional:salary, timestamp = 1418035791555,value = 50000

1 row(s) in 0.0100 seconds

The subsequent command will update the city value of the employee named ‘Raju’ to Delhi.

hbase(main):002:0> put ’emp’,’row1′,’personal:city’,’Delhi’

0 row(s) in 0.0400 seconds

The updated table looks as follows where you can observe the city of Raju has been changed to ‘Delhi’.

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

ROW          COLUMN + CELL

row1 column = personal:name, timestamp = 1418035791555, value = raju

row1 column = personal:city, timestamp = 1418274645907, value = Delhi

row1 column = professional:designation, timestamp = 141857555,value = manager

row1 column = professional:salary, timestamp = 1418039555, value = 50000

1 row(s) in 0.0100 seconds

Updating Data Using Java API

You can update the data in a particular cell using the put() method. Follow the steps given below to update an existing cell value of 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 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 Put Class

To insert data into HBase Table, the add() method and its variants are employed. This method belongs to Put, therefore instantiate the put class. This class requires the row name you want to insert the data into, in string format. You can instantiate the Put class as shown below.

Put p = new Put(Bytes.toBytes(“row1”));

Step 4: Update an Existing Cell

The add() method of Put class is employed to insert data. It requires 3 byte arrays representing column family, column qualifier (column name), and the value to be inserted, respectively. Insert data into HBase table using the add() method as shown below.

p.add(Bytes.toBytes(“coloumn family “), Bytes.toBytes(“column

name”),Bytes.toBytes(“value”));

p.add(Bytes.toBytes(“personal”),

Bytes.toBytes(“city”),Bytes.toBytes(“Delih”));

Step 5: Save the Data in Table

After inserting the required rows, save the changes by adding the put instance to the put() method of the HTable class as shown below.

hTable.put(p);

Step 6: Close HTable Instance

After creating data in HBase Table, close the HTable instance using the close() method as shown below.

hTable.close();

Given below is the complete program to update data in a particular table.

import java.io.IOException;

 

import org.apache.hadoop.conf.Configuration;

 

import org.apache.hadoop.hbase.HBaseConfiguration;

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

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

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

 

public class UpdateData{

 

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

 

// Instantiating Configuration class

Configuration config = HBaseConfiguration.create();

 

// Instantiating HTable class

HTable hTable = new HTable(config, “emp”);

 

// Instantiating Put class

//accepts a row name

Put p = new Put(Bytes.toBytes(“row1”));

 

// Updating a cell value

p.add(Bytes.toBytes(“personal”),

Bytes.toBytes(“city”),Bytes.toBytes(“Delih”));

 

// Saving the put Instance to the HTable.

hTable.put(p);

System.out.println(“data Updated”);

 

// closing HTable

hTable.close();

}

}

Compile and execute the above program as shown below.

$javac UpdateData.java

$java UpdateData

The subsequent should be the output:

data Updated

 

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

Leave a Message

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