Important HBase Java API Classes

Read more about »
  • Java 9 features
  • Read about Hadoop
  • Read about Storm
  • Read about Storm

In this tutorial, we’ll be looking at the HBase Java Client/Admin library classes. HBase is written in Java and provides Java API to communicate with it. Java API is the fastest way to communicate with HBase. Before we get into programs, let us see some of the important Classes/Interfaces that will be used later on.

Class HBaseAdmin

HBaseAdmin is a class representing the Admin. This class belongs to the org.apache.hadoop.hbase.client package. HBaseAdmin is no longer a client API. It is marked InterfaceAudience.Private indicating that this is an HBase-internal class. Using this class, you can perform administrative tasks.

Some of the important Methods and Description of HBaseAdmin class are:

void addColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily)

Add a column family to an existing table

boolean tableExists(TableName tableName)

Check if table exists or not

void createTable(TableDescriptor desc)

Creates a new table

void deleteColumnFamily(TableName tableName, byte[] columnFamily)

Delete a column family from a table

void deleteTable(TableName tableName)

Deletes a table

void disableTable(TableName tableName)

Disable table and wait on completion

void enableTable(TableName tableName)

Enable a table

List getRegions(TableName tableName)

Get the regions of a given table

HTableDescriptor[] listTables()

List all the userspace tables

void majorCompactRegionServer(ServerName serverName)

Major compact all regions on the region server

Class HTableDescriptor

[Deprecated-will be removed in HBase 3.0.0]

HTableDescriptor contains the details about an HBase table such as the descriptors of all the column families, is the table a catalog table, -ROOT- or hbase:meta , if the table is read only, the maximum size of the memstore, when the region split should occur, coprocessors associated with it etc...

Some of the important Methods and Description of HTableDescriptor class are:

HTableDescriptor addFamily(HColumnDescriptor family)

Adds a column family.

HColumnDescriptor[] getColumnFamilies()

Returns an array all the HColumnDescriptor of the column families of the table.

TableName getTableName()

Get the name of the table

boolean isMetaTable()

Checks if the table is a hbase:meta table

As of HBase release 2.0.0, HTableDescriptor will be removed in HBase 3.0.0. Use TableDescriptorBuilder to build HTableDescriptor.

Class HBaseConfiguration

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

Some of the important Methods and Description of HBaseConfiguration class are:

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

Creates a Configuration with HBase resources

static void merge(org.apache.hadoop.conf.Configuration destConf, org.apache.hadoop.conf.Configuration srcConf)

Merge two configurations.

Class HTable

An implementation of Table interface. Used to communicate with a single HBase table. Lightweight. Obtain an instance from a Connection and call close() afterwards. Table can be used to get, put, delete or scan data from a table.

Some of the important Methods and Description of HTable class are:

void delete(Delete delete)

Deletes the specified cells/row.

Result get(Get get)

Extracts certain cells from a given row.

void put(Put put)

Puts some data in the table.

Class Put

Used to perform Put operations for a single row. It belongs to the org.apache.hadoop.hbase.client package.

Some of the important Methods and Description of Put class are:

Put add(Cell cell)

Add the specified KeyValue to this Put operation.

Put addColumn(byte[] family, byte[] qualifier, byte[] value)

Add the specified column and value to this Put operation.

Class Get

Used to perform Get operations on a single row. Some of the important Methods and Description of Get class are:

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

Get the column from the specific family with the specified qualifier.

Get addFamily(byte[] family)

Get all columns from the specified family.

Class Delete

Used to perform Delete operations on a single row. Some of the important Methods and Description of Delete class are:

Delete add(Cell cell)

Add an existing delete marker to this Delete object.

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

Delete the latest version of the specified column.

Delete addFamily(byte[] family)

Delete all versions of all columns of the specified family.

Class Result

This class is used to get a single row result of a Get or a Scan query. Convenience methods are available in this class that return various Map structures and values directly. This class is NOT THREAD SAFE. Some of the important Methods and Description of Result class are:

List getColumnCells(byte[] family, byte[] qualifier)

Return the Cells for the specific column.

NavigableMap getFamilyMap(byte[] family)

Map of qualifiers to values.

byte[] getRow()

Method for retrieving the row key that corresponds to the row from which this Result was created.

byte[] getValue(byte[] family, byte[] qualifier)

Get the latest version of the specified column.