The operations that are the basic blocks of data model are Get
, Put
, Scan
, and Delete
, using which we can read, write, and delete records from an HBase table. We will discuss these operations in detail now.
The Get
operation can fetch certain records from an HBase table. It is similar to the select [fields] where RowKey=<Row Key value here>
statement in relational databases, where we fetch a row from the table.
The following is the representation of Get
:
public Result get(Get get)throws IOException
In the preceding code, the Get
operation can be provided as a single get
object out of a list of get
objects as get(List<Get> gets)
. It is specified by Get
in the HTableInterface
interface given by HBase. The Get
operation receives the get
parameter, which objects the data that is to be fetched from the table. It returns data of the particular row, which is specified in the get
object as an HBase Result
object, and this throws IOException
when not able to read.
We will see how to use these methods in Java in Chapter 8, Coding HBase in Java, and Chapter 9, Advance Coding in Java for HBase.
On HBase shell, it can be used as follows:
get 'table name', 'row key',<filters>
The Put
operation adds a new row of data to a table or updates/overrides a specific row of data. It is executed through HTable.put()
or HTable.batch()
, which is a batch write operation.
This takes put
as parameter. We can see its use as follows:
public void put(Put put) throws InterruptedIOException,RetriesExhaustedWithDetailsException
This also takes a single put
object or a list of put
objects to write a set of values in a table.
The Scan
operation can be used to read multiple rows of data in contrast to Get
where we need to specify a set of rows to read data. However, in the case of a scan, we can iterate through a range of rows or all the rows in a table.
It can be used as follows (Java code):
HBaseConfiguration conf = HBaseConfiguration.create(); HTable table1 = new HTable(conf, "hbaseTable"); Scan scanObj = new Scan(); ResultScannerrs = htable.getScanner(scanObj);
Also, we can iterate through a result-set object and get each row in the result object.
The Delete
operation removes a row or a set of rows from a table. It is executed through HTable.delete()
. Once a row is set to be deleted, it is marked as tombstone, and once compaction takes place, the row is finally deleted or removed from a table.
public void delete (Delete delete) throws IOException
delete
is specified as an interface of HTableInterface
, takes the delete
object or delete
list as a parameter, and throws IOException if any intermediate exception occurs.
The Delete
happens for the following:
3.145.9.148