hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Lucene-hadoop Wiki] Update of "Hbase/FAQ" by stack
Date Fri, 28 Sep 2007 21:51:35 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Lucene-hadoop Wiki" for change notification.

The following page has been changed by stack:

The comment on the change is:
Answered question looking for sample code

New page:
'''1. [#1 Can someone give an example of basic API-usage going against hbase?]'''

The two main client-side entry points are [http://lucene.zones.apache.org:8080/hudson/job/Hadoop-Nightly/javadoc/org/apache/hadoop/hbase/HBaseAdmin.html
H!BaseAdmin] and [http://lucene.zones.apache.org:8080/hudson/job/Hadoop-Nightly/javadoc/org/apache/hadoop/hbase/HTable.html
H!Table].  Use H!BaseAdmin to create, drop, list, enable and disable tables.  Use it also
to add and drop table column families.  For adding, updating and deleting data, use HTable.
 Here is some pseudo code absent error checking, imports, etc., that creates a table, adds
data, does a fetch of just-added data and then deletes the table.

{{{// First get a conf object.  This will read in the configuration
// that is out in your hbase-*.xml files such as location of the
// hbase master node.
HBaseConfiguration conf = new HBaseConfiguration();
// Create a table named 'test' that has two column families,
// one named 'content, and the other 'anchor'.  The colons
// are required for column family names.
HTableDescriptor desc = new HTableDescriptor("test");
desc.addFamily(new HColumnDescriptor(new Text("content:"));
desc.addFamily(new HColumnDescriptor(new Text("anchor:"));
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor[] tables = admin.listTables();
// New table should be in list of returned tables.
// Or you could call admin.exists();

// Add content to 'column:' on a row named 'row_x'
Text row = new Text("row_x");
long id = table.startUpdate(row);
table.put(id, "content:",
  "some content".getBytes(HConstants.UTF8_ENCODING));

// Now fetch the content just added
byte data[] = table.get(row, "content:");

// Delete the table.

For further examples, check out the hbase unit tests.  These are probably your best source
for sample code.  Start with the code in org.apache.hadoop.hbase.TestHBaseCluster.  It does
a general table setup and then performs various client operations on the created table: loading,
scanning, deleting, etc.

Don't forget your client will need a running hbase instance to connect to (See the ''Getting
Started'' section toward the end of this 
Hbase Package Summary] page). 

View raw message