Hot questions for Using Cassandra in php

Question:

I have the following counter column family:

CREATE TABLE subscription_counter (
    subscription_id timeuuid,
    amount counter,
    PRIMARY KEY(subscription_id)
);

When in cqlsh and run the following query, it works as intended and amount is incremented by 1.

UPDATE subscription_counter SET amount = amount + 1 WHERE subscription_id = 840e5f80-2fc7-11e5-9597-a1ae67be6e20

However from the Datastax-PHP library (http://datastax.github.io/php-driver/), the following query throws an Exception.

$statement = $session->prepare("UPDATE subscription_counter SET amount = amount + ? WHERE subscription_id = ?");
$result = $session->execute($statement, new Cassandra\ExecutionOptions(array(
    'arguments' => array(1, $subscription_id)
)));

Exception:

PHP Fatal error:  Uncaught exception 'Cassandra\Exception\InvalidQueryException' with message 'Expected 8 or 0 byte long (4)' in /var/www/vhosts/cassandra_test/v4import.php:193
Stack trace:
#0 /var/www/vhosts/cassandra_test/v4import.php(193): Cassandra\DefaultSession->execute(Object(Cassandra\PreparedStatement), Object(Cassandra\ExecutionOptions))
#1 /var/www/vhosts/cassandra_test/v4import.php(116): processUser(Object(Cassandra\DefaultSession), 'stuart.armstron...', 'stu', 'armstrong', Array)
#2 {main}
  thrown in /var/www/vhosts/cassandra_test/v4import.php on line 193

php -v

PHP 5.6.11 (cli) (built: Jul 12 2015 20:21:03)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

java -version

OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

I have tried casting 1 as a float but that does not work as intended and produces huge numbers that don't make sense. I have tried google, but can only find this stackoverflow question on how to unpack an 8 byte int, but I can't see how to create one from that.

Has anyone used counters from this library before? Could this be a php config issue?

I am using the library correctly as far as I know as all other queries seem to be working fine.

Please let me know if I can provide any more useful info.


Answer:

I figured out Cassandra provides a Bigint object, and when using that it works.

$int = new Cassandra\Bigint('1');
$statement = $session->prepare("UPDATE subscription_counter SET amount = amount + ? WHERE subscription_id = ?");
$result = $session->execute($statement, new Cassandra\ExecutionOptions(array(
        'arguments' => array($int, $subscription_id)
)));

Question:

Is it possible to execute a batch of select statements using dse cassandra or should i consider a design change?

The reason is i have a lot of select queries i wish to execute against my db cluster and not sure about going about it. I have deleted all my secondary indexes so im not using those anymore.


Answer:

That won't work and even if it would, it isn't adviseable.

  1. You won't recieve the results in a way that you can use, no result set
  2. Even if that worked, the batch query would be much less performant than doing them serially due to the way Cassandra batching is implemented.

Batching only works well if the keys (write executions) are distributed in an equal way, and this is only worth it if you want to do all the updates as a transaction. So in summary you should definitely consider a design change

Question:

In order for my data to become searchable in solr which key space should I use for all of my Cassandra tables?

I have the following keyspaces after starting solr:

        system_traces
        solr_admin
        system
        dse_system

Answer:

You shouldn't use any of those keyspaces for creating your own tables. You need to create your own keyspace, then create your table in that keyspace and then create a solr core on the keyspace on the table.

How you do this will depend on the version of DataStax Enterprise you are running. On 4.8 you can to this through dsetool with the following command:

dsetool create_core keyspace.table generateResources=true reindex=true

You will then be able to perform search queries against that table.

Here is the current search documentation for Solr search on DataStax Enterprise.