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

歡迎訪問 生活随笔!

生活随笔

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

python

python Hbase Thrift pycharm 及引入包

發布時間:2025/5/22 python 138 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python Hbase Thrift pycharm 及引入包 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cp -r hbase/ /usr/lib/python2.7/site-packages/

官方示例子
http://code.google.com/p/hbase-thrift/source/browse/trunk/python/test/tables.py
http://yannramin.com/2008/07/19/using-facebook-thrift-with-python-and-hbase/
http://wiki.apache.org/hadoop/Hbase/ThriftApi

將生成的hbase目錄copy到python的包下 cp
-r hbase /usr/lib/python2.4/site-packages/ 3。啟動hbase和thrift服務 ./bin/start-hbase.sh ./bin/hbase-daemon.sh start thrift 好像需要源碼,我反正沒找到src目錄,忘記了 。。。。。。 忘記當初自己怎么裝的了。 # --*-- coding:utf-8 --*--import sys import time# 所有thirft編程都需要的 from thrift import Thrift from thrift.transport import TSocket, TTransport from thrift.protocol import TBinaryProtocol # Hbase的 客戶端代碼 from hbase import ttypes from hbase.Hbase import Client, ColumnDescriptor, Mutation# make socket 這里配置的是hbase zookeeper的地址,因為master只負責負載均衡,讀寫由zookeeper協調 transport = TSocket.TSocket('localhost', 9090)# buffering is critical . raw sockets are very slow transport = TTransport.TBufferedTransport(transport)# wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport)# create a client to use the protocol encoder client = Client(protocol)# connect transport.open()t = 'tab2'# 掃描所有表獲取所有表名稱 print 'scanning tables ......' for table in client.getTableNames():print 'found:%s' % tableif client.isTableEnabled(table):print ' disabling table: %s' % t# 置為無效 client.disableTable(table)print 'deleting table: %s' % t# 刪除表 client.deleteTable(table)# 創建表 columns = [] col = ColumnDescriptor() col.name = 'entry:' col.maxVersions = 10 columns.append(col) col = ColumnDescriptor() col.name = 'unused:' columns.append(col)try:print 'creating table : % s' % tclient.createTable(t, columns) except Exception, ae:print 'Warn:' + ae.message# 插入數據 invalid = 'foo-\xfc\xa1\xa1\xa1\xa1\xa1' valid = 'foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB'# non-utf8 is fine for data mutations = [Mutation(column='entry:foo', value=invalid)] print str(mutations) client.mutateRow(t, 'foo', mutations) # foo is row key# try empty strings # cell value empty mutations = [Mutation(column='entry:foo', value='')] # rowkey empty client.mutateRow(t, '', mutations)#this row name is valid utf8 mutations = [Mutation(column='entry:foo', value=valid)] client.mutateRow(t, valid, mutations)# run a scanner on the rows we just created # 全表掃描 print 'starting scanner...' scanner = client.scannerOpen(t, '', ['entry:'])r = client.scannerGet(scanner) while r:#printRow(r[0])r = client.scannerGet(scanner) print 'scanner finished '# 范圍掃描 columnNames = [] for (col, desc) in client.getColumnDescriptors(t).items():print 'column with name:', desc.nameprint desccolumnNames.append(desc.name + ':')print 'stating scanner...' scanner = client.scannerOpenWithStop(t, '00020', '00040', columnNames)r = client.scannerGet(scanner) while r:# printRow(r[0])r = client.scannerGet(scanner)client.scannerClose(scanner) print 'scanner finished'# 關閉socket transport.close()

?






?






現在我們就可以用python來和hbase通信了#
-*-coding:utf-8 -*- #!/usr/bin/python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from hbase import Hbase from hbase.ttypes import ColumnDescriptor,Mutation,BatchMutationclass HbaseWriter:""" IP地址端口表名""" def __init__(self,address,port,table='user'):self.tableName = table#建立與hbase的連接self.transport=TTransport.TBufferedTransport(TSocket.TSocket(address,port))self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)self.client=Hbase.Client(self.protocol)self.transport.open()tables = self.client.getTableNames()if self.tableName not in tables:print "not in tables"self.__createTable()self.write("hell,babay!!!")self.read()#關閉def __del__(self):self.transport.close()#建表def __createTable(self):col1 = ColumnDescriptor(name="person:",maxVersions=1)col2 = ColumnDescriptor(name="contents:",maxVersions=1)col3 = ColumnDescriptor(name="info:",maxVersions=1)self.client.createTable(self.tableName,[col1,col2,col3])def write(self,content):row="abc"mutations=[Mutation(column="person:",value=content),Mutation(column="info:",value=content)]self.client.mutateRow(self.tableName,row,mutations)def read(self):scannerId = self.client.scannerOpen(self.tableName,"",["contents:",])while True:try:result = self.client.scannerGet(scannerId)except:breakcontents = result.columns["contents:"].value#print contentsself.client.scannerClose(scannerId)if __name__ == "__main__":client = HbaseWriter("192.168.239.135","9090","person")我們看下使用thrift生成的代碼中都提供了那些方法提供的方法有: void enableTable(Bytes tableName) enable表 void disableTable(Bytes tableName) disable表 bool isTableEnabled(Bytes tableName) 查看表狀態 void compact(Bytes tableNameOrRegionName) void majorCompact(Bytes tableNameOrRegionName) getTableNames() getColumnDescriptors(Text tableName) getTableRegions(Text tableName) void createTable(Text tableName, columnFamilies) void deleteTable(Text tableName) get(Text tableName, Text row, Text column) getVer(Text tableName, Text row, Text column, i32 numVersions) getVerTs(Text tableName, Text row, Text column, i64 timestamp, i32 numVersions) getRow(Text tableName, Text row) getRowWithColumns(Text tableName, Text row, columns) getRowTs(Text tableName, Text row, i64 timestamp) getRowWithColumnsTs(Text tableName, Text row, columns, i64 timestamp) getRows(Text tableName, rows) getRowsWithColumns(Text tableName, rows, columns) getRowsTs(Text tableName, rows, i64 timestamp) getRowsWithColumnsTs(Text tableName, rows, columns, i64 timestamp) void mutateRow(Text tableName, Text row, mutations) void mutateRowTs(Text tableName, Text row, mutations, i64 timestamp) void mutateRows(Text tableName, rowBatches) void mutateRowsTs(Text tableName, rowBatches, i64 timestamp) i64 atomicIncrement(Text tableName, Text row, Text column, i64 value) void deleteAll(Text tableName, Text row, Text column) void deleteAllTs(Text tableName, Text row, Text column, i64 timestamp) void deleteAllRow(Text tableName, Text row) void deleteAllRowTs(Text tableName, Text row, i64 timestamp) ScannerID scannerOpenWithScan(Text tableName, TScan scan) ScannerID scannerOpen(Text tableName, Text startRow, columns) ScannerID scannerOpenWithStop(Text tableName, Text startRow, Text stopRow, columns) ScannerID scannerOpenWithPrefix(Text tableName, Text startAndPrefix, columns) ScannerID scannerOpenTs(Text tableName, Text startRow, columns, i64 timestamp) ScannerID scannerOpenWithStopTs(Text tableName, Text startRow, Text stopRow, columns, i64 timestamp) scannerGet(ScannerID id) scannerGetList(ScannerID id, i32 nbRows) void scannerClose(ScannerID id)

?

?

?

http://blog.csdn.net/poechant/article/details/6618264

http://mmicky.blog.163.com/blog/static/150290154201311801519681/? 按照這個配置python hbase開發環境

編程前切換到/usr/program/python/hbase?? 然后運行python

>>>from thrift.transport import TSocket
>>>from thrift.protocol import TBinaryProtocol
>>>from hbase import Hbase

都不報錯,但是到pycharm報錯,原因時python默認搜索當前目錄。

到pycharm 需要把 /usr/program/python/hbase 添加到pycharm的path

操作步驟:File>>setting>>project interpreter>>python interpreter>>>paths>>>+ 把/usr/program/python/hbase 文件夾添加進去就好了。

__author__ = 'root'from thrift.transport import TSocket from thrift.protocol import TBinaryProtocol from hbase import Hbasetransport = TSocket.TSocket("localhost", 9090) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol) transport.open() tabs = client.getTableNames() print tabs

?

總結

以上是生活随笔為你收集整理的python Hbase Thrift pycharm 及引入包的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 中文字幕免费看 | 亚洲欧美日韩在线不卡 | 欧美日韩在线播放 | 欧美性受xxxx黑人猛交88 | 久久久久亚洲av无码网站 | 亚洲无毛| 成人久久久久久久 | 日韩a在线| 亚洲国产日韩欧美在线观看 | 乱熟女高潮一区二区在线 | 国产福利91精品一区二区三区 | 黄色大片一级 | 偷拍精品一区二区三区 | 色国产精品 | 91成人免费电影 | 欧洲一区二区在线观看 | 高清av在线 | 一久久久久 | 国产精品9191| 国产精品成人av久久 | 久久精品国产免费 | 黄色三级网站 | 在线观看欧美精品 | 成人免费看黄 | 五月天黄色网址 | 国产一区二区三区四区五区美女 | 蜜臀久久99静品久久久久久 | 欧美丝袜一区二区三区 | a国产精品 | 欧美日韩一二区 | 亚洲性激情 | 国产999视频 | 成人激情久久 | 欧美综合一区二区三区 | 看久久| 国产伦精品一区二区三区视频1 | 8mav在线| 久久久久久欧美精品se一二三四 | 日本成人一区 | 午夜精品剧场 | 日韩少妇内射免费播放18禁裸乳 | 五月婷婷啪啪 | 玉女心经是什么意思 | 一本色道久久综合精品婷婷 | 91小视频在线观看 | 无码一区二区三区视频 | 欧亚一区二区 | 青青精品| 欧洲av片 | 日韩在线电影一区 | 伊人av影院 | 日韩精品国产精品 | 欧美日韩一区二区区别是什么 | 日本一区不卡视频 | 黄色大片毛片 | www.男人的天堂.com | 国产中年熟女高潮大集合 | 夜夜躁狠狠躁日日躁 | 亚洲欧美日本一区二区 | 免费的av网站 | 国产一区二区三区电影在线观看 | 99er视频 | 青青久操 | 人妻丰满熟妇av无码区免 | 日本成人在线免费观看 | 亚洲一区二区三区加勒比 | 一眉道姑| 欧美女人交配视频 | 日本视频www色 | 91精品国产综合久久久密臀九色 | 无码人妻精品一区二区三应用大全 | www午夜 | 韩国三级中文字幕hd浴缸戏 | 久久久久看片 | 欧美bbbbb | 干欧美 | 国产日韩精品一区二区三区 | 日本中文字幕第一页 | 双乳被四个男人吃奶h文 | 日本色婷婷 | 欧美日韩在线视频免费观看 | 亚洲久热 | 涩av| 久久六六| 国产精品一二三四 | 国产精品日韩专区 | 欧美顶级毛片在线播放 | 国产精品男同 | 欧美一级全黄 | 日韩欧美一二三区 | 亚洲一区二区三区四区五区xx | 亚洲v日本 | 精品久久久在线观看 | 五月开心播播网 | 快播在线视频 | 久久久久久久九九九九 | 大陆农村乡下av | 欧美特黄aaaaaa | 色香天天|