我想從Perl腳本連接到Apache Hive但我發現了以下錯誤:當我嘗試使用Thrift :: API :: HiveClient執行語句時,爲什麼會收到錯誤「Thrift :: TException = HASH(0x122b9e0)」?
Thrift::TException=HASH(0x122b9e0)
我用Hadoop版本2.7.0運行,蜂巢版本1.1.0,和節儉:: API :: HiveClient版本0.003。下面是該腳本我使用:
#!/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();
}
難道這是一個版本的問題或造成的是什麼東西?
我也嘗試運行以下腳本,它自帶的Thrift-API-HiveClient-0.003
分佈:
#!/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;
};
我得到以下輸出:
[email protected]:~/perl_script$ perl test-thrift.pl
Connected
ZOMG
$VAR1 = bless({
'message' => 'Missing version identifier',
'code' => 0
}, 'Thrift::TException');
通過使我HiveServer2 NOSASL認證後修改hive-site.xml,我現在得到了一個不同的錯誤:
[email protected]:~/perl_script$ perl test-thrift.pl
Connected
ZOMG
$VAR1 = bless({
'message' => 'Invalid method name: \'execute\'',
'code' => 1
}, 'TApplicationException');
它的工作使用Thrift::API::HiveClient2
[email protected]:~/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;
};
[email protected]:~/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 = '';
錯誤來自哪裏?從'new','connect','execute'或'fetchAll'?另外,你可以轉儲哈希來看看裏面有什麼? – choroba
錯誤來自'execute'。你能告訴我從哪裏可以得到哈希錯誤的詳細信息。 –