我想使用Perl连接到基于Hadoop的Hive数据存储区.Hive允许使用Thrift接口(http://wiki.apache.org/hadoop/Hive/HiveClient)进行连接,并且Perl有一个Thrift实现(例如http://metacpan.org/pod/Thrift :::XS ) .但是,我找到的唯一一个Thrift客户端是Cassandra客户端.
如果这样的客户存在,或者如何创建它的任何想法?也许甚至可以连接而不明确定义一个?
(PS - 还有一个到Hive的ODBC/JDBC接口,但是安装这些模块是一个令人头痛的问题,并且是最后的手段)
谢谢!
经过一些阅读(最值得注意的是:blog.fingertap.org/?1a253760),我成功创建了一个Perl Thrift客户端,并使用它来查询我的服务器.
脚步:
下载,构建和安装Thrift:http://incubator.apache.org/thrift/download/.不要忘记在lib/perl中安装代码.
在Hive安装(http://svn.apache.org/viewvc/hive/)的下方,从Hive的SVN下载基础架构的.thrift文件.我使用过的文件:fb303.thrift,queryplan.thrift,hive_metastore.thrift和thrift_hive.thrift.我已手动定位它们,但可能有更好的方法.
使用thrift生成Perl代码:
thrift -r --gen perl hive_service.thrift
注意:我必须为所需的包构建目录树,并使用-I该树的根指令.我从错误节俭中得到了所需的结构,但同样,可能有更优雅的方式来做到这一点.
现在,以下Perl代码,围绕Hive的客户端Wiki中的python示例行编写,对我有用:
use Thrift;
use Thrift::Socket;
use Thrift::FramedTransport;
use Thrift::BinaryProtocol;
use lib <LOCATION OF GENERATED PERL CODE>;
use ThriftHive;
# init variables ($host, $port, $query)
#
my $socket = Thrift::Socket->new($host, $port);
my $transport = Thrift::BufferedTransport->new($socket);
my $protocol = Thrift::BinaryProtocol->new($transport);
my $client = ThriftHiveClient->new($protocol);
eval {$transport->open()}; #do something with Exceptions
eval {$client->execute($query)};
for (my $i = 0; $i < $count; $i++)
{
my $row;
eval {$row = $client->fetchOne()};
#use $row
}
$transport->close();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5289 次 |
| 最近记录: |