CentOS6.5下通过Thrift使用Python连接操作hive 安装配置记录

参考博客:http://blog.csdn.net/jiedushi/article/details/7531722

1. 安装Thrift

1.安装依赖库

yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel 
  1. 下载链接thrift-0.10.0
  1. 解压安装
tar xvf thrift-0.10.0.tar.gz
cd thrift-0.10.0
./configure
make
sudo make install

./configure报错configure: error: Bison version 2.5 or higher must be installed on the system!
yum的base源默认安装的bison版本为2.4.1太低,下载bison-2.5安装包编译安装

 wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz tar xvf  tar xvf
 bison-2.5.1.tar.gz  cd bison-2.5.1 ./configure make sudo make install

回到thrift文件夹下重新执行./configure

2. 复制Hive文件

cp -r $HIVE_PATH/lib/py/* /usr/local/lib/python2.7/site-packages

3. 启动hiveserver2

hiveserver2 &

4. Python中编程

Hive官网的示例代码:https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-Python

import sys
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
 
try:
    transport = TSocket.TSocket('localhost', 10000)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
 
    client = ThriftHive.Client(protocol)
    transport.open()
 
    client.execute("CREATE TABLE r(a STRING, b INT, c DOUBLE)")
    client.execute("LOAD TABLE LOCAL INPATH '/path' INTO TABLE r")
    client.execute("SELECT * FROM r")
    while (1):
      row = client.fetchOne()
      if (row == None):
        break
      print row
    client.execute("SELECT * FROM r")
    print client.fetchAll()
 
    transport.close()
 
except Thrift.TException, tx:
    print '%s' % (tx.message)

不过收不到响应,问题待解决

转载于:https://www.cnblogs.com/KattyJoy/p/6540125.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值