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

python3.7通過thrift操作hbase的示例代碼

 更新時(shí)間:2020年01月14日 09:23:55   作者:CPP.LA  
HBase是一個(gè)分布式的、面向列的開源數(shù)據(jù)庫,其是Apache的Hadoop項(xiàng)目的子項(xiàng)目。這篇文章主要介紹了python3.7通過thrift操作hbase的示例代碼,需要的朋友可以參考下

HBase是一個(gè)分布式的、面向列的開源數(shù)據(jù)庫,其是Apache的Hadoop項(xiàng)目的子項(xiàng)目。HBase不同于一般的關(guān)系數(shù)據(jù)庫,它是一個(gè)適合于非結(jié)構(gòu)化數(shù)據(jù)存儲(chǔ)的數(shù)據(jù)庫。另一個(gè)不同的是HBase基于列的而不是基于行的模式。其數(shù)據(jù)結(jié)構(gòu)類似與Redis的key-value模式。

 

python3.7 通過 thrift , rpc 接口操作 hbase ,指定依賴庫為: thrift 和 hbase-thrift 。 然而我們 在 python3.7 環(huán)境中發(fā)現(xiàn) hbase-thrift-0.20.4 無法被支持, hbase-thrift 官方僅推薦用于 python2.x 。 于是有了下邊的 patch 版本 和 patch 版本寫法的客戶端。

patch 版本下載,適用于 python 3.x : http://dl.cpp.la/Archive/hbase-thrift-0.20.4.patch.tgz

卸載 hbase-thrift-0.20.4 版本

# pip3 list | grep hbase-thrift
>> hbase-thrift    0.20.4
# pip3 uninstall hbase-thrift -y
>> Successfully uninstalled hbase-thrift-0.20.4

安裝 hbase-thrift-0.20.4.patch 版本(支持 python3.x )

wget http://dl.cpp.la/Archive/hbase-thrift-0.20.4.patch.tgz
tar -zxvf hbase-thrift-0.20.4.patch.tgz
cd hbase-thrift-0.20.4.patch
python3 setup.py install

檢測安裝是否成功

# pip3 list | grep hbase-thrift
>> hbase-thrift    0.20.4.patch
Python3.7 操作 hbase-thrift-patch 客戶端代碼示例
from thrift.transport import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
 
from hbase import Hbase
from hbase.ttypes import ColumnDescriptor
from hbase.ttypes import Mutation
 
class HBaseClient(object):
 
  def __init__(self):
    self.__ip = HBASE_URI.get("HOST")
    self.__port = HBASE_URI.get("PORT")
    self.__transport = self.createSocket
    protocol = TBinaryProtocol.TBinaryProtocol(self.__transport)
    self.__client = Hbase.Client(protocol)
    self.__transport.open()
 
  @property
  def createSocket(self):
    CS = TSocket.TSocket(self.__ip, self.__port)
    CS.setTimeout(60*1000)
    return TBufferedTransport(CS)
 
  def __del__(self):
    self.__transport.close()
 
  def get_tables(self):
    """
    get all table name
    :return: table name list
    """
    return self.__client.getTableNames()
 
  def create_table(self, table, *columns):
    """
    create table
    :param table: table name
    :param columns: columns name , variable parameter
    """
    func = lambda col: ColumnDescriptor(col)
    column_families = list(map(func, columns))
    self.__client.createTable(table, column_families)
 
  def delete_table(self, table):
    '''
    delete table in hbase
    :param table: tableName
    :return:
    '''
    if self.__client.isTableEnabled(table):
      self.__client.disableTable(table)
    self.__client.deleteTable(table)
 
  def put(self, table, row, columns):
    """
    add record
    :param table: table name
    :param row:
    :param columns:
    :return:
    """
    self.__client.mutateRow(table, row, [Mutation(column=k, value=v) for k, v in columns.items()])
 
  def delete(self, table, row, column):
    """
    delete record
    :param table: table name
    :param row:
    """
    self.__client.deleteAll(table, row, column)
 
  def scan(self, table, start_row="", columns=None):
    """
    get record
    :param table: table name
    :param start_row:
    :param columns:
    """
    scanner = self.__client.scannerOpen(table, start_row, columns)
    while True:
      r = self.__client.scannerGet(scanner)
      if not r:
        break
      yield dict([(k, v.value) for k, v in r[0].columns.items()])
if __name__ == "__main__":
  client = HBaseClient()
  for v in client.scan('studentd', columns={"cpp.la":"https://cpp.la"}):
    print(v)
by:cpp.la

ps:python3.7連接hbase

pip安裝thrift 和hbase 包

from thrift.transport import TSocket,TTransport
from thrift.protocol import TBinaryProtocol,TCompactProtocol
from hbase import Hbase
socket = TSocket.TSocket('10.1.21.35',port=9090)
socket.setTimeout(5000)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport) //不使用這個(gè)協(xié)議
protocol = TCompactProtocol.TCompactProtocol(transport)
client = Hbase.Client(protocol)
socket.open()
table = client.getTableNames()
print(table)

總結(jié)

以上所述是小編給大家介紹的python3.7通過thrift操作hbase的示例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • python異常的傳遞知識點(diǎn)總結(jié)

    python異常的傳遞知識點(diǎn)總結(jié)

    在本篇文章里小編給大家整理的是一篇關(guān)于python異常的傳遞知識點(diǎn)總結(jié),有興趣的朋友們可以學(xué)習(xí)下。
    2021-06-06
  • 利用Python制作簡易的核酸檢測日歷

    利用Python制作簡易的核酸檢測日歷

    這篇文章主要為大家詳細(xì)介紹了如何利用Python語言制作簡易的核酸檢測日歷,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以動(dòng)手嘗試一下
    2022-09-09
  • Pandas 稀疏數(shù)據(jù)結(jié)構(gòu)的實(shí)現(xiàn)

    Pandas 稀疏數(shù)據(jù)結(jié)構(gòu)的實(shí)現(xiàn)

    如果數(shù)據(jù)中有很多NaN的值,存儲(chǔ)起來就會(huì)浪費(fèi)空間。為了解決這個(gè)問題,Pandas引入了一種叫做Sparse data的結(jié)構(gòu),來有效的存儲(chǔ)這些NaN的值,本文就來詳細(xì)的介紹了一下,感興趣的可以了解一下
    2021-07-07
  • Python中Arrow庫的時(shí)間操作技法總結(jié)

    Python中Arrow庫的時(shí)間操作技法總結(jié)

    Arrow是一個(gè)功能強(qiáng)大、易用且具有優(yōu)雅設(shè)計(jì)的Python日期時(shí)間庫,它建立在Python的datetime模塊之上,旨在彌補(bǔ)datetime模塊在處理日期時(shí)間時(shí)的一些不足之處,下面我們就來了解一下Arrow庫的常見時(shí)間操作吧
    2023-12-12
  • 如何在python中使用openpyxl庫讀寫Excel.xlsx文件(有參考列程)

    如何在python中使用openpyxl庫讀寫Excel.xlsx文件(有參考列程)

    這篇文章主要給大家介紹了關(guān)于如何在python中使用openpyxl庫讀寫Excel.xlsx文件的相關(guān)資料,openpyxl是一個(gè)第三方庫,可以處理xlsx格式的Excel文件,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-06-06
  • Python服務(wù)器創(chuàng)建虛擬環(huán)境跑代碼

    Python服務(wù)器創(chuàng)建虛擬環(huán)境跑代碼

    本文主要介紹了Python服務(wù)器創(chuàng)建虛擬環(huán)境跑代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • pytorch模型預(yù)測結(jié)果與ndarray互轉(zhuǎn)方式

    pytorch模型預(yù)測結(jié)果與ndarray互轉(zhuǎn)方式

    今天小編就為大家分享一篇pytorch模型預(yù)測結(jié)果與ndarray互轉(zhuǎn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • ubuntu22.04將python源切換為清華源的方法

    ubuntu22.04將python源切換為清華源的方法

    在使用pip命令安裝python的一些庫時(shí),由于默認(rèn)服務(wù)器在國外,因此下載需要很長時(shí)間,本文主要介紹了ubuntu22.04將python源切換為清華源的方法,感興趣的可以了解一下
    2023-12-12
  • python opencv實(shí)現(xiàn)旋轉(zhuǎn)矩形框裁減功能

    python opencv實(shí)現(xiàn)旋轉(zhuǎn)矩形框裁減功能

    這篇文章主要為大家詳細(xì)介紹了python opencv實(shí)現(xiàn)旋轉(zhuǎn)矩形框裁減功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • 使用Python在Word文檔中添加,刪除和回復(fù)批注

    使用Python在Word文檔中添加,刪除和回復(fù)批注

    在文檔協(xié)作與審閱場景中,高效管理批注是提升團(tuán)隊(duì)效率的關(guān)鍵環(huán)節(jié),下面我們就來看看如何使用Python在Word文檔中實(shí)現(xiàn)添加、刪除和回復(fù)批注的操作吧
    2025-03-03

最新評論

兴隆县| 五台县| 外汇| 财经| 阿城市| 明光市| 拜城县| 宜阳县| 丁青县| 滨海县| 海伦市| 滦南县| 易门县| 天全县| 康乐县| 嘉鱼县| 建德市| 仙居县| 怀柔区| 栾城县| 突泉县| 达孜县| 芦山县| 遂平县| 衡山县| 和静县| 绥宁县| 陈巴尔虎旗| 虎林市| 甘泉县| 临沭县| 昆山市| 那曲县| 南康市| 盈江县| 茌平县| 土默特左旗| 谷城县| 都昌县| 云龙县| 孝感市|