HBASE-4267 book.xml - data model edits
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1162621 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7aa6268778
commit
4199e1ae02
|
@ -635,6 +635,61 @@ admin.enableTable(table);
|
|||
specifies a <literal>cell</literal> in HBase.
|
||||
Cell content is uninterrpreted bytes</para>
|
||||
</section>
|
||||
<section xml:id="data_model_operations">
|
||||
<title>Data Model Operations</title>
|
||||
<para>The four primary data model operations are Get, Put, Scan, and Delete. Operations are applied via
|
||||
<link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/HTable.html">HTable</link> instances.
|
||||
</para>
|
||||
<section xml:id="get">
|
||||
<title>Get</title>
|
||||
<para><link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/Get.html">Get</link> returns
|
||||
attributes for a specified row. Gets are executed via
|
||||
<link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/HTable.html#get%28org.apache.hadoop.hbase.client.Get%29">
|
||||
HTable.get</link>.
|
||||
</para>
|
||||
</section>
|
||||
<section xml:id="put">
|
||||
<title>Put</title>
|
||||
<para><link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/Put.html">Put</link> 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
|
||||
<link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/HTable.html#put%28org.apache.hadoop.hbase.client.Put%29">
|
||||
HTable.put</link> (writeBuffer) or <link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/HTable.html#batch%28java.util.List%29">
|
||||
HTable.batch</link> (non-writeBuffer).
|
||||
</para>
|
||||
</section>
|
||||
<section xml:id="scan">
|
||||
<title>Scans</title>
|
||||
<para><link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/Scan.html">Scan</link> allow
|
||||
iteration over multiple rows for specified attributes.
|
||||
</para>
|
||||
<para>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".
|
||||
<programlisting>
|
||||
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
|
||||
}
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section xml:id="delete">
|
||||
<title>Delete</title>
|
||||
<para><link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/Delete.html">Delete</link> removes
|
||||
a row from a table. Deletes are executed via
|
||||
<link xlink:href="http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/client/HTable.html#delete%28org.apache.hadoop.hbase.client.Delete%29">
|
||||
HTable.delete</link>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section xml:id="versions">
|
||||
<title>Versions<indexterm><primary>Versions</primary></indexterm></title>
|
||||
|
@ -728,25 +783,26 @@ admin.enableTable(table);
|
|||
<section xml:id="default_get_example">
|
||||
<title>Default Get Example</title>
|
||||
<para>The following Get will only retrieve the current version of the row
|
||||
<programlisting>
|
||||
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 </programlisting>
|
||||
<programlisting>
|
||||
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
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section xml:id="versioned_get_example">
|
||||
<title>Versioned Get Example</title>
|
||||
<para>The following Get will return the last 3 versions of the row.
|
||||
<programlisting>
|
||||
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
|
||||
</programlisting>
|
||||
<programlisting>
|
||||
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
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<title>Put</title>
|
||||
|
||||
|
@ -763,24 +819,25 @@ admin.enableTable(table);
|
|||
<section xml:id="implicit_version_example">
|
||||
<title>Implicit Version Example</title>
|
||||
<para>The following Put will be implicitly versioned by HBase with the current time.
|
||||
<programlisting>
|
||||
Put put = new Put(Bytes.toBytes(row));
|
||||
put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), Bytes.toBytes( data));
|
||||
htable.put(put);
|
||||
</programlisting>
|
||||
<programlisting>
|
||||
Put put = new Put(Bytes.toBytes(row));
|
||||
put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), Bytes.toBytes( data));
|
||||
htable.put(put);
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section xml:id="explicit_version_example">
|
||||
<title>Explicit Version Example</title>
|
||||
<para>The following Put has the version timestamp explicitly set.
|
||||
<programlisting>
|
||||
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);
|
||||
</programlisting>
|
||||
<programlisting>
|
||||
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);
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
|
Loading…
Reference in New Issue