You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Enrico Sola <so...@gmail.com> on 2016/08/25 14:14:12 UTC

Exception while using LIST on Cassandra + PHP

Hello to everyone, I'm pretty new to Cassandra and I'm working on PHP based projects.
For interface PHP with Cassandra I use the DataStax PHP driver, which lately has been updated to the version 1.2.2 and now I've a trouble while using LIST data type: when I try to use a prepared statement and I pass a Collection object as parameter I got the error "Invalid value type".
Here's a simple test:

try{
	$cluster = Cassandra::cluster()->build();
	$session = $cluster->connect('test');
	$statement = new Cassandra\SimpleStatement('CREATE TABLE IF NOT EXISTS list_test (name VARCHAR, id UUID, date TIMESTAMP, values LIST<VARCHAR>, PRIMARY KEY((name), id)) WITH CLUSTERING ORDER BY (id ASC);');
	$session->execute($statement);
	$list = new Cassandra\Collection(Cassandra::TYPE_VARCHAR);
	$list->add('foo');
	$list->add('bar');
	$statement = $session->prepare('INSERT INTO list_test (name, id, date, values) VALUES (?, uuid(), toTimestamp(now()), ?) IF NOT EXISTS;');
	$result = $session->execute($statement, new Cassandra\ExecutionOptions(array('arguments' => array('Test', $list))));
	while ($result) {
		foreach ($result as $row) {
			if ( !isset($row['[applied]']) || $row['[applied]'] !== true ){
				echo 'FAIL';
			}
		}
		$result = $result->nextPage();
	}
	echo 'OK';
}catch(Exception $ex){
	echo var_dump($ex);
}

Here's the var_dump result of the Collection object:

object(Cassandra\Collection)#11 (2) { ["type"]=> object(Cassandra\Type\Set)#12 (1) { ["valueType"]=> object(Cassandra\Type\Scalar)#13 (1) { ["name"]=> string(7) "varchar" } } ["values"]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } } 

And here there's the exception thrown:

object(Cassandra\Exception\InvalidArgumentException)#15 (7) { ["message":protected]=> string(18) "Invalid value type" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(16777229) ["file":protected]=> string(47) "/var/www/lab/Resources/_install/bin/install.php" ["line":protected]=> int(24) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(47) "/var/www/lab/Resources/_install/bin/install.php" ["line"]=> int(24) ["function"]=> string(7) "execute" ["class"]=> string(24) "Cassandra\DefaultSession" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> object(Cassandra\PreparedStatement)#14 (0) { } [1]=> object(Cassandra\ExecutionOptions)#10 (0) { } } } [1]=> array(4) { ["file"]=> string(22) "/var/www/lab/index.php" ["line"]=> int(146) ["args"]=> array(1) { [0]=> string(47) "/var/www/lab/Resources/_install/bin/install.php" } ["function"]=> string(12) "include_once" } } ["previous":"Exception":private]=> NULL } 

Now my question is: I'm doing something wrong or this is a bug in the DataStax driver?
For avoid sending another message I've also another question, it's normal that databases like MySQL or SQLite takes less that 1 ms for run a query while Cassandra takes about ten times more time? (I'm talking on PHP)

DATABASES BENCHMARK:

MySQL:
TABLE CREATION: 0.0015501976013184 SECONDS.
INSERT: 0.00049901008605957 SECONDS.
SELECT: 7.1525573730469E-6 SECONDS.

CASSANDRA:
TABLE CREATION: 0.080638885498047 SECONDS.
INSERT: 0.038239002227783 SECONDS.
SELECT: 0.025631904602051 SECONDS.

SQLITE 3:
TABLE CREATION: 0.0025551319122314 SECONDS.
INSERT: 0.012134075164795 SECONDS.
SELECT: 7.1048736572266E-5 SECONDS.

My software enviroment for this test:

PHP 7.0.8
NGINX 1.4.6
Ubuntu 14.04 LTS
MySQL 5.5.50
Cassandra 3.0.8 (DataStax PHP Driver 1.2.2)
SQLite 3

Thanks for help,

Enrico.