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

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

如何使用python在hbase里進(jìn)行模糊查詢

如何使用python在hbase里進(jìn)行模糊查詢

慕斯王 2018-10-10 09:09:59
查看完整描述

1 回答

?
猛跑小豬

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

#導(dǎo)入thrift和habse包
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 *

#此處可以修改地址和端口
host = '192.168.1.1'
#默認(rèn)端口為9090
port = 9090
#要查詢的表名
table = 'table_name'
#定義一個(gè)過濾器,此為關(guān)鍵步驟
filter = "RowFilter(=,'regexstring:.3333.')" #此行原創(chuàng):)
# Make socket
transport = TSocket.TSocket(host, port)
# Buffering is critical. Raw sockets are very slow
# 還可以用TFramedTransport,也是高效傳輸方式
transport = TTransport.TBufferedTransport(transport)
# Wrap in a protocol
#傳輸協(xié)議和傳輸過程是分離的,可以支持多協(xié)議
protocol = TBinaryProtocol.TBinaryProtocol(transport)
#客戶端代表一個(gè)用戶
client = Hbase.Client(protocol)
#打開連接
try:
transport.open()
scan.filterString=filter
scanner = client.scannerOpenWithScan(table, scan)
except Exception:
finally:
client.scannerClose(scan)
transport.close()

連接代碼網(wǎng)上一搜一大堆,非原創(chuàng),來源已不可考,非本人研究成果;

關(guān)鍵就是這個(gè):"RowFilter(=,'regexstring:.3333.')"
這個(gè)過濾器要寫對(duì),hbase有十幾種內(nèi)置的過濾器方法,有幾種比較運(yùn)算符和比較器,上面這個(gè)是正則方式,即'regexstring:.3333.';
過濾器整個(gè)雙引號(hào)里面的內(nèi)容會(huì)通過thrift傳給hbase服務(wù)端處理,下劃線這部分正則要支持java的正則要求不然會(huì)報(bào)錯(cuò)

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

添加回答

舉報(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)