HBase Client API – HTable, Put, Get, Delete, Result

Boost your career with Free Big Data Courses!!

In this HBase article, we will discuss the whole concept of HBase Client API. Also, we will introduce Class HTable to understand well. In order to perform CRUD operations on HBase tables, we use Client API for HBase. Also, in this HBase tutorial, we will see HBase client example.

So, let’s understand HBase Client API.

What is HBase Client API?

Basically, to perform CRUD operations on HBase tables we use Java client API for HBase. Since HBase has a Java Native API and it is written in Java thus it offers programmatic access to DML (Data Manipulation Language).

i. Class HBase Configuration

This class adds HBase configuration files to a Configuration. It belongs to the org.apache.hadoop.hbase package.

ii. Method

static org.apache.hadoop.conf.Configuration create()

To create a Configuration with HBase resources, we use this method.

Class HTable in HBase Client API

An HBase internal class which represents an HBase table is HTable. Basically, to communicate with a single HBase table, we use this implementation of a table. It belongs to the org.apache.hadoop.hbase.client class.

a. Constructors

i. HTable()

ii. HTable(TableName tableName, ClusterConnection connection, ExecutorService pool)

We can create an object to access an HBase table, by using this constructor.

b. Methods

i. void close()

Basically, to release all the resources of the HTable, we use this method.

ii. void delete(Delete delete)

The method “void delete(Delete delete)” helps to delete the specified cells/row.

iii. boolean exists(Get get)

As specified by Get, it is possible to test the existence of columns in the table, with this method.

iv. Result get(Get get)

This method retrieves certain cells from a given row.

v. org.apache.hadoop.conf.Configuration getConfiguration()

It returns the Configuration object used by this instance.

vi. TableName getName()

This method returns the table name instance of this table.

vii. HTableDescriptor getTableDescriptor()

It returns the table descriptor for this table.

viii. byte[] getTableName()

This method returns the name of this table.

ix. void put(Put put)

We can insert data into the table, by using this method.

Class Put in HBase Client API

In order to perform put operations for a single row, we use this class. This class belongs to the org.apache.hadoop.hbase.client package.
a. Constructors

i. Put(byte[] row)

We can create a Put operation for the specified row, by using this constructor.

ii. Put(byte[] rowArray, int rowOffset, int rowLength)

However, to make a copy of the passed-in row key to keep local, we use it.

iii. Put(byte[] rowArray, int rowOffset, int rowLength, long ts)

We can make a copy of the passed-in row key to keep local, by using this constructor.

iv. Put(byte[] row, long ts)

Basically, to create a Put operation for the specified row, using a given timestamp, we use it.

b. Methods

i. Put add(byte[] family, byte[] qualifier, byte[] value)

The method “Put add(byte[] family, byte[] qualifier, byte[] value)” adds the specified column and value to this Put operation.

ii. Put add(byte[] family, byte[] qualifier, long ts, byte[] value)
With the specified timestamp, it adds the specified column and value, as its version to this Put operation.

iii. Put add(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value)
This method adds the specified column and value, with the specified timestamp as its version to this Put operation.

iv. Put add(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value)
With the specified timestamp, it adds the specified column and value, as its version to this Put operation.

Class Get in HBase Client API

To perform Get operations on a single row, we use this class. It belongs to the org.apache.hadoop.hbase.client package.
a. Constructor

i. Get(byte[] row)

It is possible to create a Get operation for the specified row, by using this constructor.

ii. Get(Get get)

b. Methods

i. Get addColumn(byte[] family, byte[] qualifier)

To retrieves the column from the specific family with the specified qualifier, this method helps.

ii. Get addFamily(byte[] family)

Whereas this one helps to retrieves all columns from the specified family.

Class Delete in HBase Client API

In order to perform delete operations on a single row, we use this Class. Instantiate a Delete object with the row to delete, to delete an entire row. It belongs to the org.apache.hadoop.hbase.client package.
a. Constructor

i. Delete(byte[] row)

To create a delete operation for the specified row, we use it.

ii. Delete(byte[] rowArray, int rowOffset, int rowLength)

This constructor creates a Delete operation for the specified row and timestamp.

iii. Delete(byte[] rowArray, int rowOffset, int rowLength, long ts)

Basically, the constructor “Delete(byte[] rowArray, int rowOffset, int rowLength, long ts)” creates a Delete operation.

iv. Delete(byte[] row, long timestamp)

Again the constructor “Delete(byte[] row, long timestamp)” also creates a Delete operation.

b. Methods

i. Delete addColumn(byte[] family, byte[] qualifier)

This method helps to delete the latest version of the specified column.

ii. Delete addColumns(byte[] family, byte[] qualifier, long timestamp)

However, to delete all versions of the specified column we use this method, especially, With a timestamp less than or equal to the specified timestamp.

iii. Delete addFamily(byte[] family)

The method “Delete addFamily(byte[] family)”  deletes all versions of all columns of the specified family.

iv. Delete addFamily(byte[] family, long timestamp)

Again, with a timestamp less than or equal to the specified timestamp, this method also deletes all columns of the specified family.

Class Result in HBase Client API 

In order to get a single row result of a Get or a Scan query, we use class result HBase Client API.
a. Constructors
i. Result()
With no KeyValue payload, it is possible to create an empty Result; returns null if you call raw Cells(), by using this constructor.

b. Methods
i. byte[] getValue(byte[] family, byte[] qualifier)
Basically, in order to get the latest version of the specified column, we use this method.
ii. byte[] getRow()
Moreover, to retrieve the row key which corresponds to the row from which this Result was created, we use this method.
So, this was all about HBase Client API. Hope you like our explanation.

Conclusion

Hence, in this HBase Client API tutorial, we have seen the whole concept of HBase Client API. Moreover, we saw Class Htable, Class put, Class Get, Class delete, and Class result in HBase client.

Also, we look at methods, constructor & examples of HBase Client API. Still, if any doubt, ask in the comment tab.

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

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