2 回答
TA贡献1848条经验 获得超10个赞
注意:正则的写法可能不对,保证能过滤出数据,但是可能不会严格匹配,正则问题请自己解决;
#导入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'
#默认端口为9090
port = 9090
#要查询的表名
table = 'table_name'
#定义一个过滤器,此为关键步骤
filter = "RowFilter(=,'regexstring:.3333.')" #此行原创:)
# Make socket
transport = TSocket.TSocket(host, port)
# Buffering is critical. Raw sockets are very slow
# 还可以用TFramedTransport,也是高效传输方式
transport = TTransport.TBufferedTransport(transport)
# Wrap in a protocol
#传输协议和传输过程是分离的,可以支持多协议
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()
- 2 回答
- 0 关注
- 1551 浏览
添加回答
举报