CQL

Cassandraemon ver 0.8 support CQL query. You can write string query and execute it.

using(var context = new CassandraContext("localhost", 9160, "Keyspace1"))
{
	// insert
	string insertCql = "insert into ColumnFamily1 (KEY, name1, name2) values ('key1', 'value1', 'value2')"; 
	CqlResult insertResult = context.ExecuteCqlQuery(insertCql);
	
	// get count
	string countCql = "select count(*) from ColumnFamily1 where KEY = 'key1'";
	CqlResult countResult = context.ExecuteCqlQuery(countCql);
	Console.WriteLine(countResult.Num);	// 2
	
	// get data
	string retrieveCql = "select * from ColumnFamily1 where KEY = 'key1'";
	CqlResult retrieveResult = context.ExecuteCqlQuery(retrieveCql);
	
	var dictionary = retrieveResult.ToFlatDictionary<string, string>();
	dictionary.ToList().ForEach(kv => Console.WriteLine(kv.Key + " = " + kv.Value));
	// name1 = value1
	// name2 = value2
}

We implemented extension method for CqlResult. You can convert data easily.

ToCassandraEntiry ()
ToFlatNameList<T> ()
ToFlatValueList<T> ()
ToFlatDictionary<TKey, TValue> ()
ToFlatValueKeyDictionary<TKey, TValue> ()
ToNameListDictionary<TKey, TListItem> ()
ToValueListDictionary<TKey, TListItem> ()
ToObjectList<T> ()
ToObjectDictionary<TKey, TValue> ()

Counter

You can register and retrieve CounterColumn in the same way as Column. If you want increment count, register CounterColumn by same name.

// insert 
var cc1 = new CounterColumn().SetNameValue("one", 1);
var cc2 = new CounterColumn().SetNameValue("two", 2);
var cc3 = new CounterColumn().SetNameValue("three", 3);

context.InsertOnSubmit("CounterColumnFamily1", "key1", new[]{cc1, cc2, cc3});
context.SubmitChanges();


// get data
var query = from x in context.CounterColumnList	// <- attention "CounterColumnList"
	    where x.ColumnFamily == "CounterColumnFamily1" &&
		  x.Key == "key1"
	    select x.ToFlatDictionary<string, long>();

query.First().ToList().ForEach(kv => Console.WriteLine(kv.Key + " = " + kv.Value));
// one = 1
// three = 3
// two = 2

Add Event

Some events are added to cassandraemon. They are useful for profiling etc.

ConnectionPool.Connected += (sender, e) => Console.WriteLine("Connected");
ConnectionPool.ConnectionFailed += (sender, e) => Console.WriteLine("ConnectionFailed");

CassandraContext.Created += (sender, e) => Console.WriteLine("Created");

using(var context = new CassandraContext("localhost", 9160, "Keyspace1"))
{
	context.Executed += (sender, e) => Console.WriteLine("Executed");
	context.Disposed += (sender, e) => Console.WriteLine("Disposed");
	
	var column = new Column().SetNameValue("name1", "value1"); 
	context.InsertOnSubmit("ColumnFamily1", "event", column);
	context.SubmitChanges();
	
	Console.WriteLine("Submitted");
}
// Connected
// Created
// Executed
// Submitted
// Disposed

New Insert API

New Insert method overload are added. You will not have to create CassandaEntity object.

using(var context = new CassandraContext("localhost", 9160, "Keyspace1"))
{
	// old version
	context.Column.InsertOnSubmit(cassandraEntity);
	context.SuperColumn.InsertOnSubmit(cassandraEntity);
	context.ColumnList.InsertOnSubmit(cassandraEntity);
	context.SuperColumnList.InsertOnSubmit(cassandraEntity);

	// new version
	context.InsertOnSubmit( "ColumnFamily1", "key1", column );
	context.InsertOnSubmit( "ColumnFamily2", "key2", superColumn );
	context.InsertOnSubmit( "ColumnFamily3", "key3", columnList );
	context.InsertOnSubmit( "ColumnFamily4", "key4", superColumnList );
}

Load balancing improvement

Load balancing is virtually unstable until this time.
We correct this feature carefully.
And We add test code for load balancing.

New Configuration

Look Configuration page.

Last edited Oct 11, 2011 at 11:46 PM by sabro, version 3

Comments

No comments yet.