Hbase使用(python3.6版)

系统 367 0

参考脚本之家

首先,安装thrift

thrift链接:https://github.com/SparksFly8/Tools

下载thrift,这里用的是thrift-0.7.0-dev.tar.gz 这个版本

            
              tar xzf thrift-0.7.0-dev.tar.gz

cd thrift-0.7.0-dev

sudo ./configure --with-cpp=no --with-ruby=no

sudo make

sudo make instal
            
          

src/main/resources/org/apache/hadoop/hbase/thrift/然后,到HBase的源码包里,找到

执行

thrift --gen py Hbase.thrift
mv gen-py/hbase/ /usr/lib/python3.6.2/site-packages/ (根据python版本可能有不同)

            
              # coding:utf-8
 
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
import hbase.ttypes 
 
import csv 
 
def client_conn():
 transport = TSocket.TSocket('hostname,like:localhost', port)
 transport = TTransport.TBufferedTransport(transport)
 protocol = TBinaryProtocol.TBinaryProtocol(transport)
 client = Hbase.Client(protocol)
 transport.open()
 return client
 
if __name__ == "__main__":
 
 client = client_conn()
 result = client.getRow("table name","row name")
 data_simple =[]
 for k, v in result[0].columns.items(): #.keys()
    data_simple.append((v.timestamp, v.value))
 writer.writerows(data)
 csvfile.close()
 csvfile_simple = open("data_xy_simple.csv", "wb")
 writer_simple = csv.writer(csvfile_simple)
 writer_simple.writerow(["timestamp", "value"])
 writer_simple.writerows(data_simple)
 csvfile_simple.close()
 print(finished)
            
          

 


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请请扫描上面二维码支持博主1元、2元、5元等您想捐的金额吧,狠狠点击下面给点支持吧

发表我的评论
最新评论 总共0条评论