Implementation:Heibaiying BigData Notes HBaseUtils PutRow
| Knowledge Sources | |
|---|---|
| Domains | NoSQL, Big_Data |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
Concrete tool for inserting data into HBase tables using Put operations provided by the HBaseUtils utility class.
Description
The HBaseUtils class provides two overloaded putRow methods for data insertion:
- Single cell -- inserts one column qualifier/value pair into a specified row and column family.
- Batch cells -- inserts multiple qualifier/value pairs into a specified row and column family in a single Put operation, minimizing RPC overhead.
Both methods obtain a Table handle from the shared connection, construct a Put object with the row key, add cell data using put.addColumn(), and execute the write via table.put(). All string values are converted to byte arrays using Bytes.toBytes().
Usage
Use the single-cell variant when updating a single column value. Use the batch variant when inserting multiple columns for the same row to reduce the number of RPC calls.
Code Reference
Source Location
code/Hbase/hbase-java-api-2.x/src/main/java/com/heibaiying/HBaseUtils.java (Lines 83-117)
Signature
// Single cell insertion
public static boolean putRow(String tableName, String rowKey,
String columnFamilyName, String qualifier,
String value) throws IOException
// Batch cell insertion
public static boolean putRow(String tableName, String rowKey,
String columnFamilyName,
List<Pair<String, String>> pairList) throws IOException
Import
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import java.util.List;
I/O Contract
Inputs (Single Cell)
| Name | Type | Required | Description |
|---|---|---|---|
| tableName | String | Yes | The name of the target HBase table. |
| rowKey | String | Yes | The row key identifying the row to insert into. |
| columnFamilyName | String | Yes | The column family name (must exist in the table schema). |
| qualifier | String | Yes | The column qualifier (column name within the family). |
| value | String | Yes | The cell value to store. |
Inputs (Batch Cells)
| Name | Type | Required | Description |
|---|---|---|---|
| tableName | String | Yes | The name of the target HBase table. |
| rowKey | String | Yes | The row key identifying the row to insert into. |
| columnFamilyName | String | Yes | The column family name (must exist in the table schema). |
| pairList | List<Pair<String, String>> | Yes | A list of qualifier/value pairs to insert into the row under the specified column family. |
Outputs
| Name | Type | Description |
|---|---|---|
| result | boolean | Returns true upon successful insertion.
|
Usage Examples
// Single cell insertion
HBaseUtils.putRow("users", "row1", "info", "name", "Alice");
// Batch cell insertion with multiple qualifier/value pairs
List<Pair<String, String>> pairs = new ArrayList<>();
pairs.add(new Pair<>("name", "Bob"));
pairs.add(new Pair<>("email", "bob@example.com"));
pairs.add(new Pair<>("age", "30"));
HBaseUtils.putRow("users", "row2", "info", pairs);
The internal implementation for the batch variant:
// Internal logic (simplified)
Table table = connection.getTable(TableName.valueOf(tableName));
Put put = new Put(Bytes.toBytes(rowKey));
for (Pair<String, String> pair : pairList) {
put.addColumn(
Bytes.toBytes(columnFamilyName),
Bytes.toBytes(pair.getFirst()),
Bytes.toBytes(pair.getSecond())
);
}
table.put(put);
table.close();
return true;