Exemple #1
0
    def testHBase(self):
        conf = HBaseConfiguration()
        tablename = "Trees"
        admin = HBaseAdmin(conf)
        if not admin.tableExists(tablename):
            sys.stderr.write('\nERROR - Table name not found:  ' + tablename +
                             '\n\n')
            exit(1)
        # From org.apache.hadoop.hbase.client, create an HTable.
        table = HTable(conf, tablename)
        print 'connection successful'

        # Create the HBaseTable Object.
        hbtable = HBaseTable(tablename, conf, admin)

        # Read a single row from the table.
        rowId = '005430000000000038000163'

        # Put a row into the table.
        row = hbtable.row(rowId)
        row.put('f', 'name', "xxxxxxxxxxxxxxxxxxxxxxx")
        row.tablePut()

        # Read the row back from the table.
        print hbtable.row(rowId).get('f', 'name')
Exemple #2
0
 def scan(self, start_row=None, end_row=None, filter=None):
     '''
     Read the table including and between start and end rows
     applying the given filter.
     '''
     if not self._table:
         self._table = HTable(self.conf, self.name)
     sc = None
     if start_row and filter:
         sc = Scan(start_row, filter)
     elif start_row and end_row:
         sc = Scan(start_row, end_row)
     elif start_row:
         sc = Scan(start_row)
     else:
         sc = Scan()
     s = self._table.getScanner(sc)
     while True:
         r = s.next()
         if r is None:
             raise StopIteration()
         yield r
Exemple #3
0
    def __init__(self, tablename, conf=None):
        if conf is None:
            conf = HBaseConfiguration()

        self.table = HTable(conf, tablename)
Exemple #4
0
 def row(self, rowId):
     if not self._table:
         self._table = HTable(self.conf, self.name)
     return HBaseRow(self._table, rowId)
Exemple #5
0
from org.apache.hadoop.hbase import HBaseConfiguration
from org.apache.hadoop.hbase.client import HTable, Get
from org.apache.hadoop.hbase.util import Bytes

conf = HBaseConfiguration.create()
table = HTable(conf, "test")
get = Get(Bytes.toBytes('row1'))
result = table.get(get)
value = result.getValue(Bytes.toBytes('cf'), Bytes.toBytes('col1'))
print Bytes.toString(value, 0, len(value))