一些阅读(最明显的是:blog.fingertap.org/?1a253760)后,我成功地创造一个Perl节俭客户端,并用它来查询我的服务器。
步骤:
下载,构建和安装节俭: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。 我已经手动找到它们,但可能有更好的方法来做到这一点。
生成节俭使用Perl代码: thrift -r --gen perl hive_service.thrift
注:我必须建立所需的包括目录树,并使用-I
指令来此树的根。我从节俭扔向我的错误中得到了必要的结构,但是再次,可能会有更多优雅的方式来做到这一点。
现在,下面的Perl代码,围绕在蜂房的客户维基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();
确实,但这只是Thrift协议模块,不是Hive客户端... – etov 2011-03-15 13:11:52