1<!-- lang:shell --> 2Jps jdk 1.5 时引入的一个工具, 可以用来查看当前主机所有 java 进程的ID 的一个命令行工具。 3[root@PROC_141 htt]# jps 4966 CassandraDaemon 522070 NameNode 62471 Jps 722218 DataNode 822426 SecondaryNameNode 910763 Elasticsearch 1015019 ResourceManager 1122779 NodeManager 122302 RunJar # 为 hive 的 进程 ID, 13 14 15 16<!-- lang: shell --> 17hive --service hiveserver # 此时 hive 监听 10000 端口 18 19 20 21<!-- lang: python --> 22#!/usr/bin/env python 23import sys 24import traceback 25sys.path.append('/opt/old/htt/hadoop/apache-hive-0.13.1-bin/lib/py') 26from hive_service import ThriftHive 27from hive_service.ttypes import HiveServerException 28from thrift import Thrift 29from thrift.transport import TSocket 30from thrift.transport import TTransport 31from thrift.protocol import TBinaryProtocol 32 33def hiveExe(sql): 34 35 try: 36 transport = TSocket.TSocket('127.0.0.1', 10000) 37 transport = TTransport.TBufferedTransport(transport) 38 protocol = TBinaryProtocol.TBinaryProtocol(transport) 39 client = ThriftHive.Client(protocol) 40 transport.open() 41 42 client.execute(sql) 43 44 print "The return value is : " 45 print client.fetchAll() 46 print "............" 47 transport.close() 48 except Thrift.TException, tx: 49 traceback.print_exc() 50 print 'exception %s' % (tx.message) 51 52if __name__ == '__main__': 53 hiveExe("select * from test") 54 55 56返回值如下, !目前还没有感觉比 普通的数据库快多少啊。。 57<!-- lang: shell --> 58[root@PROC_141 htt]# python2.7 hive_python.py 59The return value is : 60['NULL\tNULL', 'NULL\tNULL', 'NULL\tNULL'] 61 ............
Python 连接 hive 查询数据
Stella981
2021-10-11
1159 0 0
点赞
收藏
评论区
加载中...