Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Greater than" where-condition on timeuuid using Datastax C# Cassandra Driver

How do I make "greater than" or "less than" where-conditions in CQL queries on the timeuuid data type using the Datastax C# driver?

I have a table in Cassandra for storing cookie history sorted by time stamp as timeuuid:

CREATE TABLE cookie_history (
    cookie_id text,
    create_date timeuuid,
    item_id text,
    PRIMARY KEY ((cookie_id), create_date)
);

The table is mapped using a C# class for querying using the Datastax C# Cassandra driver:

[Table("cookie_history")]
public class CookieHistoryDataEntry
{
    [PartitionKey(1)]
    [Column("cookie_id")]
    public string CookieID;

    [ClusteringKey(1)]
    [Column("create_date")]
    public Guid CreateDate;

    [Column("item_id")]
    public string ItemID;
}

For a given cookie I want all items after a given time stamp.

        var myTimeUuid = new Guid("5812e74d-ba49-11e3-8d27-27303e6a4831");
        var table = session.GetTable<CookieHistoryDataEntry>();
        var query = table.Where(x => x.CookieID == myCookieId
                                  && x.CreateDate > myTimeUuid);

But this (x.CreateDate > myTimeUuid) gives me a compile time error:

Operator '>' cannot be applied to operands of type 'System.Guid' and 'System.Guid'
like image 229
user628904 Avatar asked Apr 02 '14 09:04

user628904


People also ask

How do I SELECT distinct rows in Cassandra?

Use the DISTINCT keyword to return only distinct (different) values of partition keys. The FROM clause specifies the table to query. You may want to precede the table name with the name of the keyspace followed by a period (.). If you do not specify a keyspace, Cassandra queries the current keyspace.

How do you use clause in Cassandra?

Using the SELECT command with the IN keyword. The IN keyword can define a set of clustering columns to fetch together, supporting a "multi-get" of CQL rows. A single clustering column can be defined if all preceding columns are defined for either equality or group inclusion.

How do I use group by in Cassandra?

The GROUP BY option can condense all selected rows that share the same values for a set of columns into a single row. Using the GROUP BY option, rows can be grouped at the partition key or clustering column level. Consequently, the GROUP BY option only accepts primary key columns in defined order as arguments.


1 Answers

It is possible to use "greater than" on timeuuid in raw CQL. So one solution is to execute raw CQL from the driver:

session.Execute(@"select * 
    from cookie_history 
    where cookie_id = 1242a96c-4bd4-8505-1bea-803784f80c18 
    and create_date > 5812e74d-ba49-11e3-8d27-27303e6a4831;");
like image 192
user628904 Avatar answered Oct 28 '22 23:10

user628904