第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在ubuntu環(huán)境下怎么利用python將數(shù)據(jù)批量導(dǎo)入數(shù)據(jù)hbase

在ubuntu環(huán)境下怎么利用python將數(shù)據(jù)批量導(dǎo)入數(shù)據(jù)hbase

胡子哥哥 2018-10-02 13:13:55
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

能夠單條導(dǎo)入就能夠批量導(dǎo)入
配置 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 的鍵值對(duì)??梢圆樵兿嚓P(guān)資料?;蛘咄ㄟ^(guò)輸出變量,觀察變量的值與類(lèi)型。
說(shuō)明:上面程序中 transport.open()進(jìn)行鏈接,在執(zhí)行完后,還需要斷開(kāi)transport.close()
目前只涉及到讀數(shù)據(jù),之后還會(huì)繼續(xù)更新其他dbase操作。

查看完整回答
反對(duì) 回復(fù) 2018-10-27
  • 1 回答
  • 0 關(guān)注
  • 1164 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)