HBase - Client API


Advertisements

This chapter describes the java client API for HBase that is used to perform CRUD operations on HBase tables. HBase is written in Java and has a Java Native API. Therefore it provides programmatic access to Data Manipulation Language (DML).

Class HBase Configuration

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

Methods and description

S.No. Methods and Description
1

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

This method creates a Configuration with HBase resources.

Class HTable

HTable is an HBase internal class that represents an HBase table. It is an implementation of table that is used to communicate with a single HBase table. This class belongs to the org.apache.hadoop.hbase.client class.

Constructors

S.No. Constructors and Description
1

HTable()

2

HTable(TableName tableName, ClusterConnection connection, ExecutorService pool)

Using this constructor, you can create an object to access an HBase table.

Methods and description

S.No. Methods and Description
1

void close()

Releases all the resources of the HTable.

2

void delete(Delete delete)

Deletes the specified cells/row.

3

boolean exists(Get get)

Using this method, you can test the existence of columns in the table, as specified by Get.

4

Result get(Get get)

Retrieves certain cells from a given row.

5

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

Returns the Configuration object used by this instance.

6

TableName getName()

Returns the table name instance of this table.

7

HTableDescriptor getTableDescriptor()

Returns the table descriptor for this table.

8

byte[] getTableName()

Returns the name of this table.

9

void put(Put put)

Using this method, you can insert data into the table.

Class Put

This class is used to perform Put operations for a single row. It belongs to the org.apache.hadoop.hbase.client package.

Constructors

S.No. Constructors and Description
1

Put(byte[] row)

Using this constructor, you can create a Put operation for the specified row.

2

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

Using this constructor, you can make a copy of the passed-in row key to keep local.

3

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

Using this constructor, you can make a copy of the passed-in row key to keep local.

4

Put(byte[] row, long ts)

Using this constructor, we can create a Put operation for the specified row, using a given timestamp.

Methods

S.No. Methods and Description
1

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

Adds the specified column and value to this Put operation.

2

Put add(byte[] family, byte[] qualifier, long ts, byte[] value)

Adds the specified column and value, with the specified timestamp as its version to this Put operation.

3

Put add(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value)

Adds the specified column and value, with the specified timestamp as its version to this Put operation.

4

Put add(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value)

Adds the specified column and value, with the specified timestamp as its version to this Put operation.

Class Get

This class is used to perform Get operations on a single row. This class belongs to the org.apache.hadoop.hbase.client package.

Constructor

S.No. Constructor and Description
1

Get(byte[] row)

Using this constructor, you can create a Get operation for the specified row.

2 Get(Get get)

Methods

S.No. Methods and Description
1

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

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

2

Get addFamily(byte[] family)

Retrieves all columns from the specified family.

Class Delete

This class is used to perform Delete operations on a single row. To delete an entire row, instantiate a Delete object with the row to delete. This class belongs to the org.apache.hadoop.hbase.client package.

Constructor

S.No. Constructor and Description
1

Delete(byte[] row)

Creates a Delete operation for the specified row.

2

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

Creates a Delete operation for the specified row and timestamp.

3

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

Creates a Delete operation for the specified row and timestamp.

4

Delete(byte[] row, long timestamp)

Creates a Delete operation for the specified row and timestamp.

Methods

S.No. Methods and Description
1

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

Deletes the latest version of the specified column.

2

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

Deletes all versions of the specified column with a timestamp less than or equal to the specified timestamp.

3

Delete addFamily(byte[] family)

Deletes all versions of all columns of the specified family.

4

Delete addFamily(byte[] family, long timestamp)

Deletes all columns of the specified family with a timestamp less than or equal to the specified timestamp.

Class Result

This class is used to get a single row result of a Get or a Scan query.

Constructors

S.No. Constructors
1

Result()

Using this constructor, you can create an empty Result with no KeyValue payload; returns null if you call raw Cells().

Methods

S.No. Methods and Description
1

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

This method is used to get the latest version of the specified column.

2

byte[] getRow()

This method is used to retrieve the row key that corresponds to the row from which this Result was created.

Advertisements