Hbase Thrift API Test

Install Thrift

$ yum groupinstall 'Development Tools' # install package group on centos

$ git clone https://github.com/apache/thrift.git

$ cd thrift

$ ./configure --with-lua=no

$ make && make install

Build Hbase Client Package

$ thrift --gen py hbase-src/hbase-1.3.1/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift

Start Hbase Thrift API

$ bin/hbase thrift start

Test Hbase Thrift API

from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import ColumnDescriptor

transport = TBufferedTransport(TSocket('192.168.20.209', '9090'))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)

client = Hbase.Client(protocol)


def list_table():
print('tables: {}'.format(client.getTableNames()))


def create_table(table_name, family_name):
c = ColumnDescriptor(family_name)
client.createTable(table_name, [c])
print('create table {}'.format(table_name.decode()))


def disable_table(table_name):
client.disableTable(table_name)
print('disaable table {}'.format(table_name.decode()))


def delete_table(table_name):
client.deleteTable(table_name)
print('delete table {}'.format(table_name.decode()))


def main():
# get all table
list_table()
# create a tables
create_table(b'test_table', b'test_family')
list_table()
# disable table
disable_table(b'test_table')
# delete table
delete_table(b'test_table')
list_table()