You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2014/06/13 19:21:31 UTC
git commit: HBASE-11337 Document how to create, modify,
delete a table using Java (Misty Stanley-Jones)
Repository: hbase
Updated Branches:
refs/heads/master 6764275ff -> 91991b72a
HBASE-11337 Document how to create, modify, delete a table using Java (Misty Stanley-Jones)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/91991b72
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/91991b72
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/91991b72
Branch: refs/heads/master
Commit: 91991b72afed8435915a12baedb407949cf1ca0e
Parents: 6764275
Author: Michael Stack <st...@apache.org>
Authored: Fri Jun 13 10:21:19 2014 -0700
Committer: Michael Stack <st...@apache.org>
Committed: Fri Jun 13 10:21:19 2014 -0700
----------------------------------------------------------------------
src/main/docbkx/book.xml | 2 +-
src/main/docbkx/external_apis.xml | 6 +-
src/main/docbkx/hbase_apis.xml | 133 +++++++++++++++++++++++++++++++++
3 files changed, 138 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/91991b72/src/main/docbkx/book.xml
----------------------------------------------------------------------
diff --git a/src/main/docbkx/book.xml b/src/main/docbkx/book.xml
index 87beac7..3e22dfd 100644
--- a/src/main/docbkx/book.xml
+++ b/src/main/docbkx/book.xml
@@ -3300,7 +3300,7 @@ All the settings that apply to normal compactions (file size limits, etc.) apply
</section>
</chapter> <!-- architecture -->
-
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="hbase_apis.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="external_apis.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="thrift_filter_language.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="cp.xml" />
http://git-wip-us.apache.org/repos/asf/hbase/blob/91991b72/src/main/docbkx/external_apis.xml
----------------------------------------------------------------------
diff --git a/src/main/docbkx/external_apis.xml b/src/main/docbkx/external_apis.xml
index c61d9e7..c0b9a3f 100644
--- a/src/main/docbkx/external_apis.xml
+++ b/src/main/docbkx/external_apis.xml
@@ -29,8 +29,10 @@
*/
-->
<title>Apache HBase External APIs</title>
-<para> This chapter will cover access to Apache HBase either through non-Java languages, or through custom protocols.
-</para>
+ <para> This chapter will cover access to Apache HBase either through non-Java languages, or
+ through custom protocols. For information on using the native HBase APIs, refer to <link
+ xlink:href="http://hbase.apache.org/apidocs/index.html">User API Reference</link> and the new <xref
+ linkend="hbase_apis" /> chapter. </para>
<section xml:id="nonjava.jvm">
<title>Non-Java Languages Talking to the JVM</title>
<para>Currently the documentation on this topic in the
http://git-wip-us.apache.org/repos/asf/hbase/blob/91991b72/src/main/docbkx/hbase_apis.xml
----------------------------------------------------------------------
diff --git a/src/main/docbkx/hbase_apis.xml b/src/main/docbkx/hbase_apis.xml
new file mode 100644
index 0000000..b803269
--- /dev/null
+++ b/src/main/docbkx/hbase_apis.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<chapter
+ version="5.0"
+ xml:id="hbase_apis"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:m="http://www.w3.org/1998/Math/MathML"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:db="http://docbook.org/ns/docbook">
+ <!--
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+ <title>Apache HBase APIs</title>
+ <para>This chapter provides information about performing operations using HBase native APIs. This
+ information is not exhaustive, and provides a quick reference in addition to the <link
+ xlink:href="http://hbase.apache.org/apidocs/index.html">User API
+ Reference</link>. The examples here are not comprehensive or complete, and should be used for
+ purposes of illustration only.</para>
+ <para>Apache HBase also works with multiple external APIs. See <xref linkend="external_apis" />
+ for more information.</para>
+
+ <example>
+ <title>Create a Table Using Java</title>
+ <para>This example has been tested on HBase 0.96.1.1.</para>
+ <programlisting>
+package com.example.hbase.admin;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
+import org.apache.hadoop.conf.Configuration;
+
+import static com.example.hbase.Constants.*;
+
+public class CreateSchema {
+
+ public static void createOrOverwrite(HBaseAdmin admin, HTableDescriptor table) throws IOException {
+ if (admin.tableExists(table.getName())) {
+ admin.disableTable(table.getName());
+ admin.deleteTable(table.getName());
+ }
+ admin.createTable(table);
+ }
+
+ public static void createSchemaTables (Configuration config) {
+ try {
+ final HBaseAdmin admin = new HBaseAdmin(config);
+ HTableDescriptor table = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
+ table.addFamily(new HColumnDescriptor(CF_DEFAULT).setCompressionType(Algorithm.SNAPPY));
+
+ System.out.print("Creating table. ");
+ createOrOverwrite(admin, table);
+ System.out.println(" Done.");
+
+ admin.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+
+
+}
+
+ </programlisting>
+ </example>
+ <example>
+ <title>Add, Modify, and Delete a Table</title>
+ <para>This example has been tested on HBase 0.96.1.1.</para>
+ <programlisting>
+public static void upgradeFrom0 (Configuration config) {
+
+ try {
+ final HBaseAdmin admin = new HBaseAdmin(config);
+ TableName tableName = TableName.valueOf(TABLE_ASSETMETA);
+ HTableDescriptor table_assetmeta = new HTableDescriptor(tableName);
+ table_assetmeta.addFamily(new HColumnDescriptor(CF_DEFAULT).setCompressionType(Algorithm.SNAPPY));
+
+ // Create a new table.
+
+ System.out.print("Creating table_assetmeta. ");
+ admin.createTable(table_assetmeta);
+ System.out.println(" Done.");
+
+ // Update existing table
+ HColumnDescriptor newColumn = new HColumnDescriptor("NEWCF");
+ newColumn.setCompactionCompressionType(Algorithm.GZ);
+ newColumn.setMaxVersions(HConstants.ALL_VERSIONS);
+ admin.addColumn(tableName, newColumn);
+
+ // Disable an existing table
+ admin.disableTable(tableName);
+
+ // Delete an existing column family
+ admin.deleteColumn(tableName, CF_DEFAULT);
+
+ // Delete a table (Need to be disabled first)
+ admin.deleteTable(tableName);
+
+
+ admin.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+ </programlisting>
+ </example>
+
+</chapter>