Hbase Python接口

http://wiki.apache.org/hadoop/Hbase/ThriftApi

首先根据Hbase.thrift文件生成Python接口代码,Hbase.thrift在Hbase的源码中有,路径src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift

Hbase Python接口
thrift --gen py Hbase.thrift 
Hbase Python接口

生成的接口文件在gen-py目录下,咱直接引用即可。

Hbase Python接口
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
import sys

sys.path.append(gen-py)
from hbase import Hbase

host = 192.168.6.1
port = 8080
transport = TBufferedTransport(TSocket(host, port))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)

client = Hbase.Client(protocol)

#取数据
results = client.getRow(Item, ‘rowkey, {})
if len(results) > 0:
    result = results[0]
    for k,v in result.columns.iteritems():
        print k, v.value

# 关闭
transport.close()
Hbase Python接口

 

Hbase Python接口,布布扣,bubuko.com

Hbase Python接口

上一篇:[译] Python 2.7.6 标准库——字符串


下一篇:如何将SAP C4C TI页面的值传递到Embedded Component里去