我试图从perl脚本连接到apache hive,但出现以下错误:
Thrift::TException=HASH(0x122b9e0)
我使用的是hadoop版本2.7.0、hive版本1.1.0和thrift::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;
};
我得到以下输出:
hduser@ubuntu:~/perl_script$ perl test-thrift.pl
Connected
ZOMG
$VAR1 = bless( {
'message' => 'Missing version identifier',
'code' => 0
}, 'Thrift::TException' );
在通过修改hive-site.xml在我的hiveserver2上启用nosal身份验证之后,我现在得到一个不同的错误:
hduser@ubuntu:~/perl_script$ perl test-thrift.pl
Connected
ZOMG
$VAR1 = bless( {
'message' => 'Invalid method name: \'execute\'',
'code' => 1
}, 'TApplicationException' );
它使用 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 = '';
2条答案
按热度按时间vm0i2vca1#
thrift::api::hiveserver是针对hiveserver的,它已经被弃用了很长时间。所有最近的hadoop发行版现在都以hiveserver2为特征,为此需要thrift::api::hiveserver2。另外,请检查get\u tables和get\u columns方法,这将提供比您在示例中尝试的更好的信息。
vcudknz32#
由于您使用的是hiveserver2,请尝试使用thrift::api::hiveclient2。如果这不起作用,您可以将一些调试打印放入客户端,以查看网络是否有任何问题,例如超时。