最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python操作 hbase 數(shù)據(jù)的方法

 更新時(shí)間:2016年12月18日 11:56:44   投稿:jingxian  
下面小編就為大家?guī)硪黄猵ython操作 hbase 數(shù)據(jù)的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

配置 thrift

python使用的包 thrift

個(gè)人使用的python 編譯器是pycharm community edition. 在工程中設(shè)置中,找到project interpreter, 在相應(yīng)的工程下,找到package,然后選擇 “+” 添加, 搜索 hbase-thrift (Python client for HBase Thrift interface),然后安裝包。

安裝服務(wù)器端thrift。

參考官網(wǎng),同時(shí)也可以在本機(jī)上安裝以終端使用。

thrift Getting Started

也可以參考安裝方法 python 調(diào)用HBase 范例

首先,安裝thrift

下載thrift,這里,我用的是thrift-0.7.0-dev.tar.gz 這個(gè)版本

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 install

然后,到HBase的源碼包里,找到

src/main/resources/org/apache/hadoop/hbase/thrift/

執(zhí)行

thrift –gen py Hbase.thrift
mv gen-py/hbase/ /usr/lib/python2.4/site-packages/ (根據(jù)python版本可能有不同)

獲取數(shù)據(jù)示例 1

# 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
# from hbase.ttypes import ColumnDescriptor, Mutation, BatchMutation
from hbase.ttypes import *

import csv


def client_conn():
 # Make socket
 transport = TSocket.TSocket('hostname,like:localhost', port)
 # 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 = Hbase.Client(protocol)
 # Connect!
 transport.open()
 return client

if __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.timestamp
  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"

會(huì)基礎(chǔ)的python應(yīng)該知道result是個(gè)list,result[0].columns.items()是一個(gè)dict 的鍵值對??梢圆樵兿嚓P(guān)資料?;蛘咄ㄟ^輸出變量,觀察變量的值與類型。

說明:上面程序中 transport.open()進(jìn)行鏈接,在執(zhí)行完后,還需要斷開transport.close()

目前只涉及到讀數(shù)據(jù),之后還會(huì)繼續(xù)更新其他dbase操作。

以上這篇python操作 hbase 數(shù)據(jù)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

渝中区| 济阳县| 久治县| 静海县| 南宫市| 丹巴县| 大丰市| 汾阳市| 大方县| 奉节县| 卢湾区| 洛南县| 衡阳县| 屯门区| 英德市| 格尔木市| 万全县| 泰兴市| 福鼎市| 公主岭市| 南和县| 霍林郭勒市| 青铜峡市| 县级市| 河北区| 清新县| 阳信县| 铅山县| 兴宁市| 高邮市| 霸州市| 资兴市| 永康市| 涞水县| 乡城县| 许昌县| 青铜峡市| 邻水| 台湾省| 高唐县| 乌鲁木齐县|