简体   繁体   中英

C# cassandra composite primary key

I'm having trouble in C# after a resent change to a Cassandra table. The original primarykey consisted of 2 parts ((person_id), car_id)which wasn't enough to identify a single row so the key got extended((person_id), car_id, purchase_date).

person_id(bigint), car_id(bigint), purchase_date(timeuuid)

After this change I'm getting some java errors

2016-01-04 14:24:42.2935|ERROR|MyModule|Error while doing work java.lang.RuntimeException: Cannot get comparator 2 in org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimeUUIDType),org.apache.cassandra.db.marshal.UTF8Type). This might due to a mismatch between the schema and the data read

I'm using the datastax 2.7.0.0 and with my query I'm retrieving all the records for a person:

this.storage.GetEntityList<MyEntity>(r => r.PersonId== personid);

public virtual IEnumerable<T> GetEntityList<T>(Expression<Func<T, bool>> predicate)
        {
            return new Table<T>(this.Session)
                .Where(predicate)
                .Execute();
        }


public class MyEntity
{
    [PartitionKey]
    [Column("person_id")]
    public long PersonId{ get; set; }

    [ClusteringKey]
    [Column("car_id")]
    public long CarId{ get; set; }

    [ClusteringKey(1)]
    [Column("purchase_date")]
    public TimeUuid PurchaseDate{ get; set; }

Ofc if I query the db with cql with a SimpleStatement instead it works like a charm(ironi), but I couldn't care less. I want to know why my solution fails.

GThe C# equivalent of Cassandra TimeUUIDType is System.Guid. See CQL data types to C# types .

And the ClusteringKey attribute constructor can take a SortOrder argument. You should try that :

[ClusteringKey(1, SortOrder.Descending)]
[Column("purchase_date")]
public Guid PurchaseDate{ get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM