使用php连接hiveserver2

qoefvg9y  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(346)

我想用php连接hiveserver2,为此我发现唯一的选择是apache-thrift可用。
但它只适用于配置单元服务器1,不适用于配置单元服务器2。在找到更多信息后,这是因为当您打开传输连接时,thrift服务器希望通过sasl进行身份验证。HiveServer2默认使用sasl—不幸的是,php缺少一个版本的tsaslclienttransport(它用作另一个TTTransport对象的 Package 器),当您打开传输连接时,它会处理sasl协商。
有没有人成功地用php连接了hiveserver2。

j5fpnvbx

j5fpnvbx1#

<?php

    // set THRIFT_ROOT to php directory of the hive distribution
    $GLOBALS['THRIFT_ROOT'] = '/lib/php/';
    // 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('SELECT * from src');
    var_dump($client->fetchAll());
    $transport->close();

?>

以下是apache网站上的文档:https://cwiki.apache.org/confluence/display/hive/hiveclient#hiveclient-PHP

相关问题