Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FluentCassandra range selection problem

I have a problem in getting some data out from Cassandra using c# and FluentCassandra. In my Cassandra keyspace i have the following super column family definition:

<ColumnFamily Name="MySCFName"
                    ColumnType="Super"
                    CompareWith="TimeUUIDType"

                CompareSubcolumnsWith="AsciiType"/>

What i would like to do is run a query on this supercolumnfamily similar to the following in sql:

select "something" from MyTable where "timestamp" between "2011-01-01 00:00:00.000" and "2011-03-01 00:00:00.000"

Following one tutorial i found i can get some data out of Cassandra with the following command:

family.Get("238028210009775").Fetch(DateTime.Parse("2011-01-01 00:00:00.000")).FirstOrDefault();

but this is equivalent in sql "timestamp" > "2011-01-01 00:00:00.000"

and so far i cannot figure out how to retrieve data from a range of values.

Any hints or help will be appreciated :) Thanks in advance, Nicola

like image 632
kefer9 Avatar asked Mar 16 '11 12:03

kefer9


People also ask

Does Cassandra support range queries?

No Range Queries in Cassandra empId here is a token, for us, it's a number, but in Cassandra is a Hashed Value. In my opinion, Cassandra is a fantastic Database, extremely good in performance and writes are free here, but before designing the tables we should know our queries beforehand for better performance.

Why are Cassandra readings so slow?

Most times read performance when using Cassandra gets decreased when some operations are done wrongly such as index interval, bloom filter false positive, consistency level, read repair chance, caching, compaction, data modeling and cluster deployment.

What does allow filtering do in Cassandra?

Cassandra will request ALLOW FILTERING as it will have to first find and load the rows containing Jonathan as author, and then to filter out the ones which do not have a time2 column equal to the specified value. Adding an index on time2 might improve the query performance.

Does Cassandra support multiple indexes?

Indexes can be created on multiple columns and used in queries. The general rule about cardinality applies to all columns indexed.


1 Answers

You should be able to do it with the following:

using (var db = new CassandraContext(keyspace: "keyspace_name", host: "localhost"))
{
    var fromDate = DateTime.Now.Subtract(new TimeSpan(0, 30, 0));
    var toDate = DateTime.Now;
    var family = db.GetColumnFamily<TimeUUIDType, AsciiType>("family_name");
    var results = family.Get("row_key")
                        .Fetch(fromDate)
                        .TakeUntil(toDate)
                        .FirstOrDefault();
}
like image 101
Mark Keats Avatar answered Sep 23 '22 16:09

Mark Keats