From 4199e1ae0203fc168a98b6753647027c7f0a2569 Mon Sep 17 00:00:00 2001 From: Doug Meil Date: Mon, 29 Aug 2011 01:20:30 +0000 Subject: [PATCH] HBASE-4267 book.xml - data model edits git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1162621 13f79535-47bb-0310-9956-ffa450edef68 --- src/docbkx/book.xml | 103 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 23 deletions(-) diff --git a/src/docbkx/book.xml b/src/docbkx/book.xml index 7e95c357f11..a4a4bf70c5c 100644 --- a/src/docbkx/book.xml +++ b/src/docbkx/book.xml @@ -635,6 +635,61 @@ admin.enableTable(table); specifies a cell in HBase. Cell content is uninterrpreted bytes +
+ Data Model Operations + The four primary data model operations are Get, Put, Scan, and Delete. Operations are applied via + HTable instances. + +
+ Get + Get returns + attributes for a specified row. Gets are executed via + + HTable.get. + +
+
+ Put + 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). + +
+
+ Scans + 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 + Delete removes + a row from a table. Deletes are executed via + + HTable.delete. + +
+ +
+
Versions<indexterm><primary>Versions</primary></indexterm> @@ -728,25 +783,26 @@ admin.enableTable(table);
Default Get Example The following Get will only retrieve the current version of the row - - Get get = new Get(Bytes.toBytes("row1")); - Result r = htable.get(get); - byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value + +Get get = new Get(Bytes.toBytes("row1")); +Result r = htable.get(get); +byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value +
Versioned Get Example The following Get will return the last 3 versions of the row. - - Get get = new Get(Bytes.toBytes("row1")); - get.setMaxVersions(3); // will return last 3 versions of row - Result r = htable.get(get); - byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value - List<KeyValue> kv = r.getColumn(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns all versions of this column - + +Get get = new Get(Bytes.toBytes("row1")); +get.setMaxVersions(3); // will return last 3 versions of row +Result r = htable.get(get); +byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value +List<KeyValue> kv = r.getColumn(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns all versions of this column +
- +
Put @@ -763,24 +819,25 @@ admin.enableTable(table);
Implicit Version Example The following Put will be implicitly versioned by HBase with the current time. - - Put put = new Put(Bytes.toBytes(row)); - put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), Bytes.toBytes( data)); - htable.put(put); - + +Put put = new Put(Bytes.toBytes(row)); +put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), Bytes.toBytes( data)); +htable.put(put); +
Explicit Version Example The following Put has the version timestamp explicitly set. - - Put put = new Put( Bytes.toBytes(row )); - long explicitTimeInMs = 555; // just an example - put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), explicitTimeInMs, Bytes.toBytes(data)); - htable.put(put); - + +Put put = new Put( Bytes.toBytes(row)); +long explicitTimeInMs = 555; // just an example +put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), explicitTimeInMs, Bytes.toBytes(data)); +htable.put(put); +
+