Need some help

Mar 12, 2012 at 12:13 PM
Edited Mar 12, 2012 at 12:16 PM

Hi 

I found your version of cassandra client much updated and still working with cassandra 1.0

I am new to the client and cassandra as well. I needed some guidance in creating the following. This might not be a particular issue but I need some help. I am new to the syntax.

Thank you

TagNo // This is the super column
{
  ID // This is the column family
   {
     // here we shall have lots of entries. (Rows)
     user1: {rate, distance, capacity}
     user2: {rate, distance, capacity}
    }    
}

Rate distance and capacity can be stored as either strings or doubles. But does not really matter at the moment.

I need to know what would be the code snippet to do so if I am using a keyspace "Test".

Thank you.

Coordinator
Mar 12, 2012 at 6:15 PM

Following code is query sample.

You can get more sample in document page.

http://cassandraemon.codeplex.com/documentation

 

using(var context = new CassandraContext("localhost", 9160, "Test"))
{
    var entitys = from x in context.SuperColumn
                    where x.Key == "user1" &&
                    x.ColumnFamily == "ID" &&
                    x.SuperColumn == "TagNo"
              select x;
                  
    foreach(CassandraEntity<SuperColumn> e in entitys)
    {
        // rate
        Console.WriteLine(e.Data.Columns[0].Name.ToUTF8());
        Console.WriteLine(e.Data.Columns[0]Value.ToDouble());

        // distance
        Console.WriteLine(e.Data.Columns[1].Name.ToUTF8());
        Console.WriteLine(e.Data.Columns[1]Value.ToDouble());

        // capacity
        Console.WriteLine(e.Data.Columns[2].Name.ToUTF8());
        Console.WriteLine(e.Data.Columns[2]Value.ToDouble());
    }
}

Mar 13, 2012 at 7:25 AM

Thank you for the code!!

Mar 13, 2012 at 10:46 AM

Sabro

I created another keyspace with the following over cassandra-CLI

create keyspace Stacks with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};

create column family StackID with column_type = 'Super' and comparator = 'UTF8Type' and subcomparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and column_metadata =

[{ column_name : 'Initial', validation_class : UTF8Type}, {column_name : 'Last', validation_class : UTF8Type}];

Now when I try to query the data using one of the operations I keep getting exception.

Probably I am not doing it properly.

var entitys = from x in context.SuperColumn
                    where x.Key == "Initial" &&
                    x.ColumnKey == "Initial" &&
                    x.SuperColumn == "StackID"
              select x;

In 'Results View' after a debug point in entitys I get

base {System.SystemException} = {"You can't specify Column in case of get SuperColumn."}

What am I doing wrong here?

Coordinator
Mar 14, 2012 at 12:40 AM

You should replace SuperColumn to Column.

var entitys = from x in context.SuperColumn
                    where x.Key == "Initial" &&
                    x.ColumnKey == "Initial" &&
                    x.Column == "StackID"
              select x;


Because SuperColumn mean ColumnPath.SuperColumn.

In case get operation for SuperColumnFamily, We should specify ColumnPath.Column = 'SuperColumnName'.

Mar 14, 2012 at 5:18 AM

OK here is how I did it

var entitys = from x in context.Column
                    where x.Key == "Initial" &&
                    x.ColumnFamily == "StackID"
              select x;