php 连接hive,php连接hive执行sql查询 | 学步园

使用php连接hive的条件

1  需要安装thrift  安装步骤

#  ./configure --without-ruby

#   make && make install

如果没有安装libevent libevent-devel的应该先安装这两个依赖库yum -y install libevent libevent-devel

安装好后启动hive thrift

# ./hive --service hiveserver >/dev/null 2>/dev/null &

查看hiveserver默认端口是否打开10000   如果打开表示成功

注:php版本要求是5.2或者以上

php连接hive代码

// php连接hive thrift依赖包路径

$GLOBALS['THRIFT_ROOT'] = '/var/www/html/hivephp/thrift/';

// load the required files for connecting to Hive

require_once $GLOBALS['THRIFT_ROOT'] . 'packages/hive_service/ThriftHive.php';

require_once $GLOBALS['THRIFT_ROOT'] . 'transport/TSocket.php';

require_once $GLOBALS['THRIFT_ROOT'] . 'protocol/TBinaryProtocol.php';

// Set up the transport/protocol/client

$transport = new TSocket('localhost', 10000);

$protocol = new TBinaryProtocol($transport);

$client = new ThriftHiveClient($protocol);

$transport->open();

// run queries, metadata calls etc

$client->execute('add jar /usr/local/hadoop/hive/lib/hive-contrib-0.7.0-cdh3u0.jar');

$client->execute('select count(1) from apilog');

var_dump($client->fetchAll());

$transport->close();

?>

将以上代码存为test.php到apache的www路径/var/www/html/中  php连接hive的依赖包放到/var/www/html/hivephp/thrift/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值