Cassandra

The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.

Slackbuild

Node up

cqlsh

http://wiki.apache.org/cassandra/GettingStarted

CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
describe keyspaces;
USE mykeyspace;
CREATE TABLE users (  user_id int PRIMARY KEY,  fname text,  lname text );
INSERT INTO users (user_id,  fname, lname)  VALUES (1745, 'john', 'smith');
INSERT INTO users (user_id,  fname, lname)  VALUES (1744, 'john', 'doe');
INSERT INTO users (user_id,  fname, lname)  VALUES (1746, 'john', 'smith');
describe tables;
SELECT * FROM users;
desc table users;
CREATE INDEX ON users (lname);
desc table users;
SELECT * FROM users WHERE lname = 'smith';

Python sample app

http://datastax.github.io/python-driver/getting_started.html

python3 cass.py

   1 from cassandra.cluster import Cluster
   2 
   3 cluster = Cluster(['127.0.0.1'])
   4 session = cluster.connect('mykeyspace')
   5 rows = session.execute('SELECT  user_id , fname , lname FROM users')
   6 for user_row in rows:
   7     print('%d %s %s'%( user_row.user_id, user_row.fname, user_row.lname) )

python3 asyncCass.py

   1 import time
   2 from cassandra.cluster import Cluster
   3 
   4 def sucessHandler(rows):
   5     print('Received data !')
   6     try:
   7         for user_row in rows:
   8             print('>>> %d %s %s'%( user_row.user_id, user_row.fname, user_row.lname) )
   9     except Exception as ex:
  10         print(ex) 
  11 
  12 def errorHandler(exception):
  13     print(exception) 
  14 
  15 if __name__=='__main__':
  16     cluster = Cluster(['127.0.0.1'])
  17     session = cluster.connect('mykeyspace')
  18     futurex = session.execute_async('SELECT  user_id , fname , lname FROM users')
  19     futurex.add_callbacks(sucessHandler,errorHandler)
  20     print('Wait 3 seconds ...')
  21     time.sleep(3)

Python types conversion

Python Type

CQL Literal Type

None

NULL

bool

boolean

float

float double

int

int

long

bigint varint counter

decimal.Decimal

decimal

str unicode

ascii varchar text

buffer bytearray

blob

date datetime

timestamp

list tuple generator

list

set frozenset

set

dict OrderedDict

map

uuid.UUID

timeuuid uuid

Cassandra (last edited 2014-08-07 21:34:25 by 73)