慕桂英546537
注意:正则的写法可能不对,保证能过滤出数据,但是可能不会严格匹配,正则问题请自己解决;#导入thrift和habse包from thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom hbase import Hbasefrom hbase.ttypes import *#此处可以修改地址和端口host = '192.168.1.1'#默认端口为9090port = 9090#要查询的表名table = 'table_name'#定义一个过滤器,此为关键步骤filter = "RowFilter(=,'regexstring:.3333.')" #此行原创:)# Make sockettransport = 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=filterscanner = client.scannerOpenWithScan(table, scan)except Exception:finally:client.scannerClose(scan)transport.close()