PHP 连接 Hive 执行 SQL 查询
来源:互联网 发布:黄金技术分析软件 编辑:程序博客网 时间:2024/05/22 13:15
Hive 中的 Thrift 脚本有两个版本的,一个有命名空间,一个没有命名空间,下面使用的是没有命名空间的版本。
无命名空间的PEAR
$ cd /opt/hive/lib/php/packages/$ mv hive_service hive_service.bak$ mv hive_service.bak/hive_service ./$ cd /opt/hive/lib/php/packages/queryplan/queryplan$ cp queryplan_types.php ../$ cd /opt/hive/lib/php/packages/hive_metastore/hive_metastore$ cp ThriftHiveMetastore.php ../
PHP
<?php$GLOBALS['THRIFT_ROOT'] = '/opt/hive/lib/php';require_once '/opt/hive/lib/php/autoload.php';require_once '/opt/hive/lib/php/Thrift.php';require_once '/opt/hive/lib/php/packages/fb303/FacebookService.php';require_once '/opt/hive/lib/php/transport/TSocket.php';require_once '/opt/hive/lib/php/protocol/TBinaryProtocol.php';require_once '/opt/hive/lib/php/packages/hive_service/ThriftHive.php';/** * @author chenliujin <liujin.chen@qq.com> * @since 2013-08-20 */class Hive{ /** * @author chenliujin <liujin.chen@qq.com> * @since 2013-08-20 */ public function query($sql) { try { // Set up the transport/protocol/client $transport = new TSocket('localhost', 10000); $transport->setSendTimeout(10000); $transport->setRecvTimeout(100000); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); // run queries, metadata calls etc $client->execute($sql); $result = $client->fetchAll(); $data = array(); foreach ($result as $row) { $row = explode("\t", $row); $data[] = $row; } $transport->close(); return $data; } catch (Exception $e) { return array(); } }}
FAQ
PHP Fatal error: Uncaught exception 'HiveServerException' with message 'Query returned non-zero code: 40000, cause: FAILED: ParseException line 5:23 cannot recognize input near 'ab' ';' '<EOF>' in expression specification' in /opt/hive/lib/php/packages/hive_service/ThriftHive.php:618
- When you write a query in the shell, you should use ';' at the end of the SQL statement, However, you CANNOT use ';' at the end of the SQL statement when you're using Java.
TSocket: timed out reading 4 bytes from localhost:10000
加大超时时间
$transport->setSendTimeout(1000000);$transport->setRecvTimeout(100000000);
- php连接hive执行sql查询
- PHP 连接 Hive 执行 SQL 查询
- php连接hive执行HQL查询
- hive 连接查询sql对比效率
- python通过thrift连接hive,异步执行查询
- php连接数据库 执行查询的方法
- python 连接数据库执行sql 查询
- spark-sql 集合hive查询数据执行日志
- hive 查询执行分析
- Hive 连接查询JOIN
- hive sql执行计划
- hive sql执行计划
- Hive执行SQL语句
- shell语句执行hive查询
- python连接 hive 执行hsql
- VS2010连接SQL Server 2008并执行查询操作
- VS2010连接SQL Server 2008并执行查询操作
- VS2010连接SQL Server 2008并执行查询操作
- [MFC]GetWindowRect和GetClientRect区别
- c# winform 中文输入法的问题.
- Vistual Studio原生开发的20条调试技巧(下)
- git book 中文版
- uva 11386 Triples (hash总是wa,于是模拟STL)
- PHP 连接 Hive 执行 SQL 查询
- JAVA 的一个小案例分析
- 在Chrome中加载未打包的扩展
- 登陆学习系统(1)
- unity3D 接鸡蛋小游戏
- Android优秀开源项目
- poll 函数
- 动态下载苹果提供的多种中文字体
- 谈Objective-C Block的实现