The four primary data model operations are Get, Put, Scan, and Delete. Operations are applied via HTable instances.
Get returns attributes for a specified row. Gets are executed via HTable.get.
Put either adds new rows to a table (if the key is new) or can update existing rows (if the key already exists). Puts are executed via HTable.put (writeBuffer) or HTable.batch (non-writeBuffer).
Scan allow iteration over multiple rows for specified attributes.
The following is an example of a on an HTable table instance. Assume that a table is populated with rows with keys "row1", "row2", "row3", and then another set of rows with the keys "abc1", "abc2", and "abc3". The following example shows how startRow and stopRow can be applied to a Scan instance to return the rows beginning with "row".
HTable htable = ... // instantiate HTable Scan scan = new Scan(); scan.addColumn(Bytes.toBytes("cf"),Bytes.toBytes("attr")); scan.setStartRow( Bytes.toBytes("row")); scan.setStopRow( Bytes.toBytes("row" + new byte[] {0})); // note: stop key != start key for(Result result : htable.getScanner(scan)) { // process Result instance }
Delete removes a row from a table. Deletes are executed via HTable.delete.