python远程访问hive
#!/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的更多相关文章
- python 连接 hive
1.python连接hive,其实是连接hiveserver,连接的包的impyla impyla安装: error: cc1plus 没有文件或目录 需要安装gcc 和g++,并且版本保持一致 er ...
- Hive 教程(九)-python with hive
本文介绍用 python 远程连接 hive,此时需要 hive 启动 hiveserver2 服务 windows 下报如下错误 thrift.transport.TTransport.TTrans ...
- python访问hive
#!/usr/bin/env python # -*- coding: utf-8 -*- # hive util with hive server2 """ @auth ...
- python操作hive 安装和测试
方法一:使用pyhive库 如上图所示我们需要四个外部包 中间遇到很多报错.我都一一解决了 1.Connection Issue: thrift.transport.TTransport.TTrans ...
- python 链接hive
http://blog.csdn.net/xubcing/article/details/8350287 http://www.centoscn.com/python/2014/0921/3801.h ...
- python 调用hive查询实现类似存储过程
需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留7月份即可 ****************ods_log_info*****************lid st ...
- python链接Hive
之前一直用thrift链接Hive,但在运行时总出现问题,一直报缺少模块的错误,装了这个模块,又报缺少那个模块,连了半天,全是泪啊! 原来thrift链接Hive的.py文件后续没人维护,是连不上的. ...
- python 读取hive数据
话不多说,直接上代码 from pyhive import hivedef pyhive(hql): conn = hive.Connection(host='HiveServer2 host', p ...
- python 连接 hive 的 HiveServer2 的配置坑
环境: hadoop 2.7.6 hive 2.3.4 Hive 的 thirft 启动: hadoop 单机或者集群需要: 启动 webhdfs 修改 hadoop 的代理用户 <proper ...
随机推荐
- python私有成员与公有成员(_和__)
python并没有对私有成员提供严格的访问保护机制. 在定义类的成员时,如果成员名以两个下划线“__”或更多下划线开头而不以两个或更多下划线结束则表示是私有成员. 私有成员在类的外部不能直接访问,需要 ...
- 初中级PHP面试基础汇总
这是我整理的一套面试题,老铁们看看就当复习了哦 相关PHP面试题 搞定PHP面试 - 函数知识点整理 php 面试题目整理 PHP面试整理 PHP面试 概述 感觉现在发面试题有些冷门,就跟昨天德国那场 ...
- java 之Thread线程相关yield()、sleep()、wait()、join()、run和start方法详解
1.sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁.也就是说如果有synchronized同步快,其他线程仍然不能访问共享数据.注意该方 ...
- 求分数序列的前n项之和
有一个分数序列 2/1,3/2,5/3,8/5,13/8,21/13,.... 求这个分数序列的前n项之和. 输入 测试数据有多组,其第一行为一个正整数k(0<k<=90),表示测试数据的 ...
- Java中TreeMap集合讲解
1.TreeSet介绍 TreeSet是一个有序集合,可以以任意顺序将元素插入到集合中,在对集合进行遍历的时候,每个元素将自动按照排序后的顺序呈现.底层使用的是二叉树(更具体点是红黑树)实现,对于元素 ...
- ZOJ 3469 区间DP Food Delivery
题解 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm ...
- unittest单元测试(测试报告生成)
自动化测试执行完成之后,我们需要生成测试报告来查看测试结果,使用HTMLTestRunner模块可以直接生产Html格式的报告. 下载地址: http://tungwaiyip.info/softwa ...
- Laya List翻页滚动方案 & List滚动源码解析
Laya List翻页滚动方案 & List滚动源码解析 @author ixenos 2019-03-29 1.List翻页滚动方案 /** * 计算下一页的起始索引, 不足时补足 * @p ...
- POJ-2318 TOYS,暴力+叉积判断!
TOYS 2页的提交记录终于搞明白了. 题意:一个盒子由n块挡板分成n+1块区 ...
- 关于JS正则表达式
去除所有P标签 content=content.replace(/<([\/]?)(p)((:?\s*)(:?[^>]*)(:?\s*))>/g, ''); 将所有的 1. ...