Search code examples
phpcassandraprepared-statementdatastaxtimeuuid

Datastax Cassandra PHP Driver: "Invalid value type" exception when using timeuuid in prepared statement


I'm trying to execute prepared statement with timeuuid value and get "Invalid value type" exception.

Here is the code:

$builder = \Cassandra::cluster();
$cluster = $builder->withContactPoints('127.0.0.1')
            ->build();

$session = $cluster->connect();
$preparedStatement = $session->prepare("SELECT * FROM test.timeuuid_test WHERE account_id = :accId and item_time_uid >= minTimeuuid(:minTime);");
$options = new ExecutionOptions([
            'arguments' => [
                'accId' => 1234,
                'minTime' => new \Cassandra\Timeuuid(1458118516)
            ]
        ]);
$session->execute($preparedStatement, $options);

I get the following exception:

"Cassandra\Exception\InvalidArgumentException : Invalid value type"

Here is the table scheme:

CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1 };

CREATE TABLE test.timeuuid_test (
  account_id int,
  item_time_uid timeuuid,
  PRIMARY KEY ((account_id), item_time_uid)
) WITH CLUSTERING ORDER BY (item_time_uid DESC);

What am I doing wrong?

I'm using PECL cassandra 1.1.0 and cassandra 2.0.15:

installed cassandra related packages: cassandra20-2.0.15-1.noarch cassandra-cpp-driver-2.2.2-1.el6.x86_64 cassandra-cpp-driver-devel-2.2.2-1.el6.x86_64


Solution

  • You're binding the wrong type to minTime: minTimeUuid takes a timestamp argument, not a timeuuid.