我是Cassandra的新手。我正在使用Datastax的Cassandra PHP驱动程序。我试图用多个插入创建批处理语句。鉴于该表型号:CQL PHP驱动程序:具有良好值的预准备语句中的值类型无效
CREATE TABLE real_time_log (
du_id int,
tag_id int,
status int,
time_stamp bigint,
value float,
PRIMARY KEY ((du_id, tag_id), status, time_stamp)
)
我试图以两种方式插入以下值:
$batch = new Cassandra\BatchStatement();
$stmt = $this->cassandraDb->prepare('insert into real_time_log'
. ' (du_id, tag_id, status, time_stamp, value) '
. 'VALUES (?, ?, ?, ?, ?)');
foreach ($curData as $cData) {
$values = explode(',', $cData);
$stmtValues = array(
'du_id' => 11111,
'tag_id' => 22222,
'status' => (int) $values[2],
'time_stamp' => new Cassandra\Bigint($values[0]),
'value' => (double) $values[1]
);
$batch->add($stmt, $stmtValues);
}
$this->cassandraDb->executeAsync($batch);
这会产生错误:
PHP Fatal error: Uncaught exception 'Cassandra\Exception\InvalidArgumentException' with message 'Invalid value type'
同时,我尝试了更直接的方法没有准备好的陈述:
$batch = new Cassandra\BatchStatement();
foreach ($curData as $cData) {
$values = explode(',', $cData);
$stmtValues = array(
11111,
22222,
(int) $values[2],
new Cassandra\Bigint($values[0]),
(double) $values[1]
);
$batch->add(new Cassandra\SimpleStatement('insert into real_time_log'
. ' (du_id, tag_id, status, time_stamp, value) '
. 'VALUES (' . implode(',', $stmtValues) . ')'));
}
$this->cassandraDb->executeAsync($batch);
这种方式一切正常,但肯定会慢很多。 也许有人可以解释我正在做的准备好的陈述方法有什么问题?
预先感谢您。
您的评论解决了这个问题。我发现一个驱动程序与标准值类型分离很奇怪,对于像C++这样的静态类型语言来说似乎很好,但是在动态php环境中它不适合其他任何东西。那么至少这是我的看法。请将您的评论转换为答案,我会接受它。谢谢 –
题外话:我刚刚发现批处理语句正在泄漏内存o.O –