Perl Thrift client to Hive?
After some reading (most notably: blog.fingertap.org/?1a253760), I succeeded in creating a Perl Thrift client, and using it to query my server.
Steps:
Download, build and install Thrift: http://incubator.apache.org/thrift/download/. Don't forget to make install the code in lib/perl.
Download the infrastructure's .thrift files from Hive's SVN, under the dist of your Hive installation (http://svn.apache.org/viewvc/hive/). The files I have used: fb303.thrift, queryplan.thrift, hive_metastore.thrift and thrift_hive.thrift. I have located them manually, but there might be better ways of doing that.
Generate the Perl code using thrift:
thrift -r --gen perl hive_service.thrift
Note: I had to build the directory tree for the required includes, and use the-I
directive to this tree's root. I got the required structure from the errors thrift threw at me, but again, there might be more elegant ways of doing that.
Now, the following Perl code, written around the lines of the python example in Hive's client Wiki, works for me:
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();
In case this is helpful, I've recently uploaded this to the CPAN:
https://metacpan.org/module/Thrift::API::HiveClient
It's still not yet fully documented, and has no tests, but I'm happy to take any patches anybody wants to send! :)