当我尝试执行带有 Thrift::API::HiveClient 的语句时,为什么会出现错误 "Thrift::TException=HASH(0x122b9e0)"?
Why do I get the error "Thrift::TException=HASH(0x122b9e0)" when I try to execute a statement with Thrift::API::HiveClient?
我正在尝试从 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 上启用 NOSASL 身份验证后,我现在收到一个不同的错误:
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 = '';
由于您使用的是 HiveServer2,请尝试使用 Thrift::API::HiveClient2。如果这不起作用,您可以将一些调试打印放入客户端以查看是否有任何与网络相关的事情发生,例如超时。
Thrift::API::HiveServer 用于 HiveServer,已弃用很长时间。所有相当新的 Hadoop 发行版现在都具有 HiveServer2,您需要 Thrift::API::HiveServer2。
此外,请检查 get_tables 和 get_columns 方法,这将为您提供比您在示例中尝试的信息更好的信息。
我正在尝试从 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 上启用 NOSASL 身份验证后,我现在收到一个不同的错误:
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 = '';
由于您使用的是 HiveServer2,请尝试使用 Thrift::API::HiveClient2。如果这不起作用,您可以将一些调试打印放入客户端以查看是否有任何与网络相关的事情发生,例如超时。
Thrift::API::HiveServer 用于 HiveServer,已弃用很长时间。所有相当新的 Hadoop 发行版现在都具有 HiveServer2,您需要 Thrift::API::HiveServer2。 此外,请检查 get_tables 和 get_columns 方法,这将为您提供比您在示例中尝试的信息更好的信息。