Dear Wiki user, You have subscribed to a wiki page or wiki category on "Hadoop Wiki" for change notification.
The following page has been changed by AndreiSavu: http://wiki.apache.org/hadoop/Hbase/Jython The comment on the change is: fixed first sample code. in sync with latest code changes. ------------------------------------------------------------------------------ {{{ import java.lang - from org.apache.hadoop.hbase import HBaseConfiguration, HBaseAdmin,\ - HTableDescriptor, HColumnDescriptor, HTable, HConstants - from org.apache.hadoop.io import Text + from org.apache.hadoop.hbase import HBaseConfiguration, HTableDescriptor, HColumnDescriptor, HConstants + from org.apache.hadoop.hbase.client import HBaseAdmin, HTable + from org.apache.hadoop.hbase.io import BatchUpdate, Cell, RowResult # First get a conf object. This will read in the configuration # that is out in your hbase-*.xml files such as location of the @@ -54, +54 @@ # 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. + tablename = "test" - tablename = "test" # some things accept Strings - tablename_text = Text(tablename) # others accept Text - desc = HTableDescriptor(tablename) desc.addFamily(HColumnDescriptor("content:")) @@ -64, +62 @@ admin = HBaseAdmin(conf) # Drop and recreate if it exists - if admin.tableExists(tablename_text): + if admin.tableExists(tablename): + admin.disableTable(tablename) - admin.deleteTable(tablename_text) + admin.deleteTable(tablename) admin.createTable(desc) tables = admin.listTables() - - table = HTable(conf, tablename_text) + table = HTable(conf, tablename) # Add content to 'column:' on a row named 'row_x' + row = 'row_x' + update = BatchUpdate(row) + update.put('content:', 'some content') + table.commit(update) - row = Text("row_x") - # Use `lock_id` here to avoid name collision with the Python builtin id function - lock_id = table.startUpdate(row) - table.put(lock_id, Text("content:"), "some content") - table.commit(lock_id) # Now fetch the content just added, returns a byte[] - data = table.get(row, Text("content:")) + data_row = table.get(row, "content:") + data = java.lang.String(data.value, "UTF8") - data_str = java.lang.String(data, "UTF8") # cast to a UTF8 string - print "The fetched row contains the value '%s'" % (data_str) + print "The fetched row contains the value '%s'" % data - # Delete the table. + admin.disableTable(desc.getName()) admin.deleteTable(desc.getName()) }}}
