3

I am trying to connect to Apache Hive from a Perl script but I'm getting the following error:

Thrift::TException=HASH(0x122b9e0)

I am running with Hadoop version 2.7.0, Hive version 1.1.0, and Thrift::API::HiveClient version 0.003. Here is the script I am using:

#!/usr/bin/perl

use English;
use Thrift::API::HiveClient;

connecttoHive();

sub connecttoHive {
    my $client = Thrift::API::HiveClient->new( host => 'localhost', port => 10000 );

    $client->connect() or die "Failed to connect";

    $client -> execute('select count(1) from Koushik.emp2');
    my $result = $client -> fetchAll();
}

Could this be caused by a version issue or is it something else?


I also tried running the following script, which comes with the Thrift-API-HiveClient-0.003 distribution:

#!/usr/bin/env perl
use lib 'lib';
use Data::Dumper;
use Try::Tiny;
use Thrift::API::HiveClient;
#use Moose;

my ($host, $port) = (localhost => 10000);

try sub {
  my $client = Thrift::API::HiveClient->new( host => $host, port => $port );
  $client->connect;
  print "Connected\n";
  $client->execute(
    q{ create table if not exists t_foo (foo STRING, bar STRING) }
  );
  $client->execute('show tables');
  print Dumper $client->fetchAll;
  print Dumper $client->getClusterStatus;
  print Dumper $client->get_fields( 'default', 't_foo');
},
catch sub {
  print "ZOMG\n";
  print Dumper($_);
  exit 1;
};

I get the following output:

hduser@ubuntu:~/perl_script$ perl test-thrift.pl
Connected
ZOMG
$VAR1 = bless( {
                 'message' => 'Missing version identifier',
                 'code' => 0
               }, 'Thrift::TException' );

After enabling NOSASL authentication on my HiveServer2 by modifying the hive-site.xml, I am now getting a different error:

hduser@ubuntu:~/perl_script$ perl test-thrift.pl
Connected
ZOMG
$VAR1 = bless( {
                 'message' => 'Invalid method name: \'execute\'',
                 'code' => 1
               }, 'TApplicationException' );

It worked using Thrift::API::HiveClient2

hduser@ubuntu:~/perl_script$ cat test-thrift-client2.pl
#!/usr/bin/env perl
use lib 'lib';
use Data::Dumper;
use Try::Tiny;
use Thrift::API::HiveClient2;
#use Moose;

my ($host, $port) = (localhost => 10000);

try sub {
  my $client = Thrift::API::HiveClient2->new( host => $host, port => $port );
  $client->connect;
  print "Connected\n";
  $client->execute(
    q{ create table if not exists t_foo (foo STRING, bar STRING) }
  );
  $client->execute('show tables');
  print Dumper $client->fetch;
# print Dumper $client->getClusterStatus;
# print Dumper $client->get_fields( 'default', 't_foo');
},
catch sub {
  print "ZOMG\n";
  print Dumper($_);
  exit 1;
};

hduser@ubuntu:~/perl_script$ perl test-thrift-client2.pl
Connected
$VAR1 = [
          [
            'drv_cdr_mp'
          ],
          [
            'emp1'
          ],
          [
            'emp3'
          ],
          [
            'emp_1'
          ],
          [
            'emp_bucket'
          ],
          [
            'emp_incr_test'
          ],
          [
            'emp_rslt'
          ],
          [
            'log_detail'
          ],
          [
            't_foo'
          ],
          [
            'test1_emp1'
          ]
        ];
$VAR2 = '';
4

2 回答 2

0

Thrift::API::HiveServer 用于 HiveServer,已被弃用很长时间。所有最近的 Hadoop 发行版现在都具有 HiveServer2,您需要 Thrift::API::HiveServer2。另外,检查 get_tables 和 get_columns 方法,这将为您提供比您在示例中尝试的更好的信息。

于 2016-05-14T23:34:45.047 回答
0

由于您使用的是 HiveServer2,请尝试使用 Thrift::API::HiveClient2。如果这不起作用,您可以将一些调试打印打印到客户端,以查看网络是否有任何事情发生,例如超时。

于 2016-03-23T23:09:07.040 回答