CQL PHP驱动程序:具有良好值的预准备语句上的值类型无效

时间:2015-10-19 12:48:30

标签: php cassandra prepared-statement cql datastax-php-driver

我是Cassandra的新手。我正在使用Datastax的Cassandra 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);

这样一切正常,但肯定会慢得多。 也许有人可以解释我正在做的准备好的陈述方法有什么问题?

提前谢谢。

2 个答案:

答案 0 :(得分:1)

乍一看,它看起来应该有效 - 您是否尝试过明确地传递(double) $values[1](将new Cassandra\Float($values[1])更改为SignInManager.SignIn(user, false, false) )?

答案 1 :(得分:0)

我已执行此操作以插入单行,并且工作正常:

$glid = 12345;
$modid = 'mobile';
$sysdate = date("YmdHis");

$sql = "insert into user (USR_ID,modid,membersince) values (?,?,?)";
$par = array(new Cassandra\Bigint($glid),$modid,new Cassandra\Bigint($sysdate));

$statement = $db->prepare($sql);
$db->execute($statement, array(
                 'arguments' => $par
));