1. 程式人生 > >使用python通過Thrift連線Hbase(Demo)

使用python通過Thrift連線Hbase(Demo)

# coding=utf-8

from thrift.transport import TSocket, TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase

socket = TSocket.TSocket('xxx.xxx.xxx.xxx', port)
socket.setTimeout(5000)

transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol) socket.open() print(client.getTableNames()) #建立表結構 column1 = ColumnDescriptor(name='personal data:') column2 = ColumnDescriptor(name='professional data:') client.createTable("empbypy",[column1,column2]) #判斷是否啟用表 if client.isTableEnabled('empbypy'): print("empbypy tb is enabled"
) else: print ("empbypy tb is disabled")