Posts

Showing posts with the label cql

CQL(Cassandra Query Language) Reference

Hi, I think now I'm eligible to publish a blog post regd CQL. I wish this blog to be a tutorial rather a Syntax provider for various CQL queries Points to remember 1. CQL doesn't support Composite Types[likely to chage] 2. CQL doesn't support Super columns 3. Counter values are returned in native format [atleast in php/using cqlsh] Why should I prefer CQL? 1. Readability 2. Ease of use 3. SQL like 4. Stable Support: PHP => My Posts using PHPCassa Python => Refer Here and Download it here Java => JDBC Driver and Example is here Ruby => This might help Creating a Keyspace: cqlsh> CREATE KEYSPACE sample WITH strategy_class = 'org.apache.cassandra.locator.SimpleStrategy' ... AND strategy_options:replication_factor = 2; Note: : => Option Specifier Use a Keyspace: cqlsh> USE sample; Note: Don't forget to USE before use 'Sample' and 'sample' are different. Create Column Family: cqlsh...

Cassandra CQL PHP Part 2

I have explained the way to execute CQL Queries from PHP via PHPCassa in my previous blogpost here  and tutorial on cql queries here It was difficult for me to remember the syntax of update and select CQL queries for Cassandra. Hence I wrote wrappers for them which are listed below Update Counter Query: /* * $counterMap => Associative array of CounterColumn names and corresponding value for given $key * Ex: UPDATE TestCounterFamily SET 'counter'='counter'+1, 'counter2'='counter2'+3 WHERE KEY='test' */ function generateUpdateCounterQuery($columnFamily, $counterMap, $key) { $colArgs = ""; foreach($counterMap as $counter => $value) { $colArgs=$colArgs."'".$counter."'='".$counter."'+".$value.", "; } $colArgs = rtrim($colArgs,", "); return "UPDATE ".$columnFamily." SET ".$colArgs." WHERE KEY='".$key."...

Cassandra CQL PHP

After lots of googling I figured out how to access counter columns value via PHPCassa + CQL. Though it might not be efficient, this is all I was able to figure out after a long struggle :) First Connecting to and Selection from Cassandra Instance via PHP using PHPCassa $pool = new ConnectionPool("Stats",$servers); $raw = $pool->get(); $rows = $raw->client->execute_cql_query("SELECT 'a' FROM Impressions WHERE KEY='xxx'", cassandra_Compression::NONE); To Return Connection $pool->return_connection($this->raw); To Update Counter value via PHPCassa $pool = new ConnectionPool("Stats",$servers); $raw = $pool->get(); $rows = $raw->client->execute_cql_query("UPDATE TestCounter SET 'counter'='counter'+1 WHERE KEY='xxx'", cassandra_Compression::NONE); You can find a wrapper here So, once you are done with fetch successfully. This is the result you may get object(cassandra_CqlResult)#...