2 启动hive 的thrift
确保以下服务开启:
hive --service hiveserver
默认端口是10000
from hive_service import ThriftHive from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol def ReadHiveTest(sql): try: tSocket = TSocket.TSocket('172.18.1.88',10000) tTransport = TTransport.TBufferedTransport(tSocket) protocol = TBinaryProtocol.TBinaryProtocol(tTransport) client = ThriftHive.Client(protocol) tTransport.open() client.execute(sql) return client.fetchAll() except Thrift.TException, tx: print '%s' % (tx.message) finally: tTransport.close() if __name__ == '__main__': showDatabasesSql = 'show databases' showTablesSql = 'show tables' selectSql = 'SELECT * FROM 07_jn_mysql_2' result = ReadHiveTest(selectSql) print(result[1])
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com