我正在使用Hypertable :: ThriftClient,并使用mutator进行大量插入。以下是代码示例:$ master,$ port和$ namespace都已定义。
Table:
show create table users; # Table schema is below
CREATE TABLE GROUP_COMMIT_INTERVAL "100" users (
'column_name_fake' MAX_VERSIONS 1,
ACCESS GROUP audience ('column_name_fake'),
)
:hypertable$ SELECT * FROM users limit 1; # displays
2342345 sf_following:1000234
2342346 sf_following:1234234
代码:
my $ht = new Hypertable::ThriftClient($master, $port);
my $ns = $ht->namespace_open($namespace);
my $users_mutator = $ht->mutator_open($ns, 'table_name', 2);
子程序:
sub batch_insert {
my ($ht, $mutator, $column_family, $row, $val) = @_;
my $keys;
my $cell;
try {
$keys = new Hypertable::ThriftGen::Key({
row => $row,
column_family => $column_family });
$cell = new Hypertable::ThriftGen::Cell({key => $keys, value => $val});
}
catch {
warn Dumper({ 'Error' => $_ });
};
$ht->mutator_set_cell($mutator, $cell);
$ht->mutator_flush($mutator);
return 1;
}
函数调用:
for(.....) { # Just for example
batch_insert($ht, $users_mutator, '', $fs, "node:$node_u");
}
这里我得到一个例外,
Hypertable::ThriftGen::ClientException=HASH(0x54d7380)
任何人都可以澄清,为什么?
编辑:为了更清晰,我添加了表格结构?
答案 0 :(得分:1)
ClientException类定义如下:
异常ClientException { 1:i32代码 2:字符串消息 }
尝试捕获异常并打印出代码(十六进制)和消息。这应该有助于查明正在发生的事情。
答案 1 :(得分:0)
FIX: So, this exception is raised is a required parameter 'column_qualifier' was not
passed as per the table design. See below:
sub batch_insert {
my ($ht, $mutator, $cf, $cq, $row, $val) = @_;
my $keys = new Hypertable::ThriftGen::Key({
row => $row,
column_family => $cf,
column_qualifier => $cq });
my $cell = new Hypertable::ThriftGen::Cell({key => $keys, value => $val});
$ht->mutator_set_cell($mutator, $cell);
#$ht->mutator_flush($mutator);
}
Calling the above function:
--------------------------
batch_insert($ht, $users_mutator, 'column_family' , 'column_qualifier, 'row_key', '');
它就像一个魅力。如果你遇到类似的问题,请告诉我,我可以提供帮助。我花了很多时间阅读Thrift api。