2011-03-13 191 views
6

我想使用Perl连接到基于Hadoop的Hive数据存储。 Hive允许使用Thrift接口(http://wiki.apache.org/hadoop/Hive/HiveClient)进行连接,并且有一个用于Perl的Thrift实现(例如http://metacpan.org/pod/Thrift::XS)。但是,我发现唯一的Thrift客户端是Cassandra客户端。Perl Thrift客户端到Hive?

任何想法,如果这样的客户存在,或如何创建它? 也许甚至有可能连接而不明确定义一个?

(PS - 还有一个ODBC/JDBC接口,蜂巢,但安装这些模块是头疼,会是最后的手段)

的感谢!

回答

8

一些阅读(最明显的是:blog.fingertap.org/?1a253760)后,我成功地创造一个Perl节俭客户端,并用它来查询我的服务器。

步骤:

  1. 下载,构建和安装节俭:http://incubator.apache.org/thrift/download/。 不要忘记在lib/perl中安装代码。

  2. 在Hive安装(http://svn.apache.org/viewvc/hive/)的基础上,从Hive的SVN下载基础架构的.thrift文件。我用过的文件:fb303.thrift,queryplan.thrift,hive_metastore.thrift和thrift_hive.thrift。 我已经手动找到它们,但可能有更好的方法来做到这一点。

  3. 生成节俭使用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(); 
2

如果这是有帮助的,我最近上传了该到CPAN:

https://metacpan.org/module/Thrift::API::HiveClient

它仍然还没有完全记录,并具有没有测试,但我我很乐意接受任何人希望发送的补丁! :)

+0

真棒工作!这也可以与Hive Server 2一起使用吗?谢谢。 – Tagar 2015-11-16 23:51:41

+0

也是,它是否可以与Kerberized集群一起使用?再次感谢。 – Tagar 2015-11-16 23:53:16

相关问题