2 回答

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個贊
注意:正則的寫法可能不對,保證能過濾出數(shù)據(jù),但是可能不會嚴(yán)格匹配,正則問題請自己解決;
#導(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'
#定義一個過濾器,此為關(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)
#客戶端代表一個用戶
client = Hbase.Client(protocol)
#打開連接
try:
transport.open()
scan.filterString=filter
scanner = client.scannerOpenWithScan(table, scan)
except Exception:
finally:
client.scannerClose(scan)
transport.close()

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個贊
#導(dǎo)入thrift和habse包 from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol .
- 2 回答
- 0 關(guān)注
- 803 瀏覽
添加回答
舉報(bào)