日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

ubuntu导入python的包_在ubuntu环境下怎么利用python将数据批量导入数据hbase

發布時間:2024/9/19 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu导入python的包_在ubuntu环境下怎么利用python将数据批量导入数据hbase 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

斯蒂芬大帝

能夠單條導入就能夠批量導入配置 thriftpython使用的包 thrift個人使用的python 編譯器是pycharm community edition. 在工程中設置中,找到project interpreter, 在相應的工程下,找到package,然后選擇 “+” 添加, 搜索 hbase-thrift (Python client for HBase Thrift interface),然后安裝包。安裝服務器端thrift。參考官網,同時也可以在本機上安裝以終端使用。thrift Getting Started也可以參考安裝方法 python 調用HBase 范例首先,安裝thrift下載thrift,這里,我用的是thrift-0.7.0-dev.tar.gz 這個版本tar xzf thrift-0.7.0-dev.tar.gzcd thrift-0.7.0-devsudo ./configure –with-cpp=no –with-ruby=nosudo makesudo make install然后,到HBase的源碼包里,找到src/main/resources/org/apache/hadoop/hbase/thrift/執行thrift –gen py Hbase.thriftmv gen-py/hbase/ /usr/lib/python2.4/site-packages/ (根據python版本可能有不同)獲取數據示例 1# coding:utf-8from thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom hbase import Hbase# from hbase.ttypes import ColumnDescriptor, Mutation, BatchMutationfrom hbase.ttypes import *import csvdef client_conn():# Make sockettransport = TSocket.TSocket('hostname,like:localhost', port)# Buffering is critical. Raw sockets are very slowtransport = TTransport.TBufferedTransport(transport)# Wrap in a protocolprotocol = TBinaryProtocol.TBinaryProtocol(transport)# Create a client to use the protocol encoderclient = Hbase.Client(protocol)# Connect!transport.open()return clientif __name__ == "__main__":client = client_conn()# r = client.getRowWithColumns('table name', 'row name', ['column name'])# print(r[0].columns.get('column name')), type((r[0].columns.get('column name')))result = client.getRow("table name","row name")data_simple =[]# print result[0].columns.items()for k, v in result[0].columns.items(): #.keys()#data.append((k,v))# print type(k),type(v),v.value,,v.timestampdata_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"會基礎的python應該知道result是個list,result[0].columns.items()是一個dict 的鍵值對。可以查詢相關資料。或者通過輸出變量,觀察變量的值與類型。說明:上面程序中 transport.open()進行鏈接,在執行完后,還需要斷開transport.close()目前只涉及到讀數據,之后還會繼續更新其他dbase操作。

總結

以上是生活随笔為你收集整理的ubuntu导入python的包_在ubuntu环境下怎么利用python将数据批量导入数据hbase的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。