Monday, March 28, 2016

Why do I get the error “Thrift::TException=HASH(0x122b9e0)” when I try to execute a statement with Thrift::API::HiveClient?

Leave a Comment

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 = ''; 

1 Answers

Answers 1

Since you are using HiveServer2, try using Thrift::API::HiveClient2. If that doesn't work, you could put some debug prints into the client to see if there is anything going on vis-a-vis the network, e.g. timeouts.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment