#!/usr/bin/python
import sys
sys.path.append('/home/zhoujie/Downloads/hive-0.7.0-cdh3u0/lib/py')
from hive_service import ThriftHive
from hive_service.ttypes import HiveServerException
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

hive_server_ip='127.0.0.1'
hive_server_port=10000
#hive_sql='select count(*) from ssp_factbids'
hive_sql="select count(*) from ssp_factbids where logdate_id='20121101'"

def hiveExe(sql):
    try:
        transport = TSocket.TSocket(hive_server_ip, hive_server_port)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        client = ThriftHive.Client(protocol)
        transport.open()

client.execute(sql)

print "The return value is : "
        print client.fetchAll()
        print "............"
        transport.close()
    except Thrift.TException, tx:
        print '%s' % (tx.message)

if __name__ == '__main__':
    hiveExe(hive_sql)

python远程访问hive的更多相关文章

  1. python 连接 hive

    1.python连接hive,其实是连接hiveserver,连接的包的impyla impyla安装: error: cc1plus 没有文件或目录 需要安装gcc 和g++,并且版本保持一致 er ...

  2. Hive 教程(九)-python with hive

    本文介绍用 python 远程连接 hive,此时需要 hive 启动 hiveserver2 服务 windows 下报如下错误 thrift.transport.TTransport.TTrans ...

  3. python访问hive

    #!/usr/bin/env python # -*- coding: utf-8 -*- # hive util with hive server2 """ @auth ...

  4. python操作hive 安装和测试

    方法一:使用pyhive库 如上图所示我们需要四个外部包 中间遇到很多报错.我都一一解决了 1.Connection Issue: thrift.transport.TTransport.TTrans ...

  5. python 链接hive

    http://blog.csdn.net/xubcing/article/details/8350287 http://www.centoscn.com/python/2014/0921/3801.h ...

  6. python 调用hive查询实现类似存储过程

    需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留7月份即可 ****************ods_log_info*****************lid st ...

  7. python链接Hive

    之前一直用thrift链接Hive,但在运行时总出现问题,一直报缺少模块的错误,装了这个模块,又报缺少那个模块,连了半天,全是泪啊! 原来thrift链接Hive的.py文件后续没人维护,是连不上的. ...

  8. python 读取hive数据

    话不多说,直接上代码 from pyhive import hivedef pyhive(hql): conn = hive.Connection(host='HiveServer2 host', p ...

  9. python 连接 hive 的 HiveServer2 的配置坑

    环境: hadoop 2.7.6 hive 2.3.4 Hive 的 thirft 启动: hadoop 单机或者集群需要: 启动 webhdfs 修改 hadoop 的代理用户 <proper ...

随机推荐

  1. 小型LAMP搭建

    一.dns的搭建 安装dns服务 yum install bind 修改dns的主配置文件 [root@234c17 named]# vim /etc/named.conf // // named.c ...

  2. RN与现有的原生app集成

    https://facebook.github.io/react-native/docs/integration-with-existing-apps.html RN可以很好地支持往一个原生的app上 ...

  3. perl学习之裸字

    use strict包含3个部分.其中之一(use strict "subs")负责禁止乱用的裸字. 这是什么意思呢? 如果没有这个限制,下面的代码也可以打印出"hell ...

  4. 零基础学Python不迷茫——基本学习路线及教程!

    什么是Python? 在过去的2018年里,Python成功的证明了它自己有多火,它那“简洁”与明了的语言成功的吸引了大批程序员与大数据应用这的注意,的确,它的实用性的确是配的上它的热度.   Pyt ...

  5. 四、10分钟ToPandas_0.24.2

    # Author:Zhang Yuan整理,版本Pandas0.24.2 # 0. 习惯上,我们会按下面格式引入所需要的包: import pandas as pd import numpy as n ...

  6. (转)Objective-C语言--属性和实例变量

    本文转自http://blog.csdn.net/addychen/article/details/39525681 使用Objective-C一段时间了,一直没有弄清楚在Objective-C中属性 ...

  7. 编写个makefile文件测试patsubst 的作用

    1 SRCS := $(wildcard *.c) 2 OBJS := $(patsubst %.c,%.o,$(SRCS) ) //把$(SRCS)中的文件.c全部换成.o文件 3 all: 4 @ ...

  8. c语言头文件以及make注意事项

    c语言头文件以及make注意事项 头文件说明:自己定义的头文件和项目文件放在一起,注意使用""而不是使用<>,系统的头文件才使用<> 当main函数要调用其 ...

  9. 【转】SQL索引一步到位

    原文:http://www.cnblogs.com/AK2012/archive/2013/01/04/2844283.html SQL索引一步到位(此文章为“数据库性能优化二:数据库表优化”附属文章 ...

  10. Android ScrollView嵌套GridView导致GridView只显示一行item

    Android ScrollView嵌套GridView导致GridView只显示一行item Android ScrollView在嵌套GridView时候,会导致一个问题发生:GridView只显 ...