Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
HBase Client API
3.
HBase Class Configuration
4.
Class HTable
5.
Class Put
6.
Class Get
7.
Class Delete
8.
Class Result
9.
FAQs
10.
Key Takeaways
Last Updated: Mar 27, 2024

HBase Client API

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

This HBase tutorial will go over the basics of the HBase Client API. We'll also go over Class HTable so you can get a better understanding. Client API for HBase is used to conduct CRUD(Create, read, update, delete) operations on HBase tables. 

So, let’s understand HBase Client API.

HBase Client API

In general, we use the Java client API for HBase to perform CRUD activities on HBase tables. HBase allows programmatic access to DML (Data manipulation language ) because it has a Java Native API developed in Java.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

HBase Class Configuration

This class is part of the org.apache.hadoop.hbase package and is used to add HBase configuration files to a Configuration.

Let's have a look at its methods and description.

Methods

Description

static org.apache.hadoop.conf.Configuration create() This method is used to construct HBase-based Configuration.

Class HTable

HTable is an HBase internal class that represents an HBase table. We use this table implementation to connect with a single HBase table. The org.apache.hadoop.hbase.client class is responsible for it.

Let's take a look at the constructors and descriptions.

Constructor Name

Descriptions

HTable()  We use this constructor to make an object to access an HBase table.

Let's have a look at its methods and descriptions.

Methods

Description

void close() This method is used to release all of HTable's resources.
void delete(Delete delete) This method is used to delete the cells/rows that have been specified.
boolean exists(Get get) We use this method to check if the table's columns exist, as requested by Get.
Result get(Get get) This method is used to get specific cells from a particular row.
org.apache.hadoop.conf.Configuration getConfiguration() This method is used to return the instance's configuration object.
TableName getName() The table name instance of the specified table is returned using this method.
HTableDescriptor getTableDescriptor() The table descriptor for speified table is returned using this method.
byte[] getTableName() The name of the specified table is returned using this method.
void put(Put put) We can insert data into the table using this method.

Class Put

This class is part of the org.apache.hadoop.hbase.client package and executes put operations on a single row.

Let's take a look at the constructors and descriptions.

Constructor

Description

Put(byte[] row) We can make a Put operation for the supplied row by using this constructor.
Put(byte[] rowArray, int rowOffset, int rowLength) Using this constructor, we can have a copy of the passed-in row key to keep local.
Put(byte[] rowArray, int rowOffset, int rowLength, long ts) We can have a copy of the passed-in row key to keeping local using this constructor
Put(byte[] row, long ts) This creates a Put operation for the specified row, using a given timestamp by using this constructor.

Let us have a look at its methods and description.

Methods

Description

Put add(byte[] family, byte[] qualifier, byte[] value) The provided column and value are added to this Put operation using this method.
Put add(byte[] family, byte[] qualifier, long ts, byte[] value) This method is used to add the supplied column and value to this Put operation, along with the specified timestamp as its version.
Put add(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value) This method adds the supplied column and value to this Put operation, along with the specified timestamp as its version.
Put add(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value) This method is used to add the supplied column and value to this Put operation, along with the specified timestamp as its version.

Class Get

The next step is to retrieve what was just saved. The Get call and corresponding classes are provided by the HTable for this purpose. The operations are divided into two types: single-row operations and operations that fetch many rows in a single request.

This class is part of the org.apache.hadoop.hbase.client package and performs Get operations on a single row.

Let us look at its constructor and description.

Constructor

Description

Get(byte[] row) We can establish a Get operation for the supplied row using this constructor.

Let us have a look at its methods and description.

Methods

Description

Get addColumn(byte[] family, byte[] qualifier) This method retrieves a column from a particular family using the specified qualifier.
Get addFamily(byte[] family) This method is used to get a list of all columns in a given family.

Class Delete

This class is part of the org.apache.hadoop.hbase.client package deletes a single row. It instantiates a Delete object with the row to delete and uses it to delete the entire row.

Let us have a look at its constructor and description.

Constructor

Description

Delete(byte[] row) For the supplied row, this constructor is used to produce a Delete operation.
Delete(byte[] rowArray, int rowOffset, int rowLength) This constructor creates a Delete action for the row and timestamps supplied.
Delete(byte[] rowArray, int rowOffset, int rowLength, long ts) This constructor creates a Delete action for the row and timestamp supplied.
Delete(byte[] row, long timestamp) This constructor creates a Delete action for the row and timestamp supplied.

Let us have a look at its methods and description.

Methods

Description

Delete addColumn(byte[] family, byte[] qualifier) This method is used to remove the most recent version of a column.
Delete addColumns(byte[] family, byte[] qualifier, long timestamp) This method deletes all versions of the specified column with a timestamp less than or equal to the timestamp specified.
Delete addFamily(byte[] family) This method is used to erase all versions of the specified family's columns.
Delete addFamily(byte[] family, long timestamp) This method deletes all columns in the selected family with a timestamp less than or equal to the supplied timestamp.

Class Result

When you use the get() method to obtain data, you'll get an instance of the Result class, which contains all matching cells. It gives you access to whatever the server returned for the given row that matches the supplied query, such as column family, column qualifier, timestamp, and so on.

This class is used to convey single row Get or Scan query results.

Let us have a look at its constructor and description.

Constructor

Description

Result() We can produce an empty Result with no KeyValue payload by using this constructor. Raw Cells returns null ().

Let us see its methods and description.

Methods

Description

byte[] getValue(byte[] family, byte[] qualifier) We may see the most recent version of a column using this way.
byte[] getRow() The row key will be retrieved using this procedure.

 

Must Read Apache Server

FAQs

  1. What is HBase?
    HBase is a column-oriented database with a configurable database structure. It mainly works on top of HDFS and also supports MapReduce tasks. HBase also supports various high-level languages for data processing.
     
  2. Why do we use HBase client API?
    We use Java client API for HBase basically to perform CRUD operations on HBase tables.
     
  3. Why is HBase faster than RDBMS?
    Hbase correlates to the ACID Properties. HBase is a column-oriented database management system based on the Hadoop Distributed File System (HDFS). It is appropriate for sparse data sets, typical in many significant data use cases.

Key Takeaways

HBase is a column-oriented database with a configurable database structure. It mainly works on top of HDFS and also supports MapReduce tasks. HBase also supports various high-level languages for data processing. In this blog, we have seen the whole concept of HBase Client API. We have seen various methods or constructors with their descriptions available in HBase Client API like Class HTable, Class Put, Class Get, Class Delete, and Class Result.

Also, try Coding Ninjas Studio to practice programming problems for your complete interview preparation. Don't stop here, Ninja; check out the Top 100 SQL Problems to get hands-on experience with frequently asked interview questions and land your dream job.

Previous article
HBase Admin API
Next article
HBase Troubleshooting
Live masterclass