Right now I have a table with three columns: GroupId
,ObjectId
and Data
, with first two defined as partition key.
Currently it works as desired: if GroupId
and ObjectId
match existing row, it gets overwritten.
I'm trying to add sorting by date, so I added third column, LastModified
and specified it as clustering key. While it works for sorting, now I have multiple rows sharing the same GroupId
and ObjectId
pairs, which is not what I need.
How can I achieve previous behaviour?
I dislike both solutions because they seem to be too complicated and performance is a big concern. Is there a better way?
Here is how i did this in case someone else faces same problem:
I have a table with GroupId
and ObjectId
as key. I'm not sure if it matters, but ObjectId
is defined as clustering key.
Then you get desired result from following view:
CREATE MATERIALIZED VIEW IF NOT EXISTS objectlistbylast
AS SELECT * FROM objectlist
WHERE groupid IS NOT NULL AND objectid IS NOT NULL AND lastmodified IS NOT NULL
PRIMARY KEY(groupid , lastmodified, objectid )
WITH CLUSTERING ORDER BY(lastmodified DESC);
Note that ordering when defining primary key matters.