You could try this. C* doesn't do it all for you, but it will efficiently
get you the right data.
-ml
-- put this in <file> and run using 'cqlsh -f <file>
DROP KEYSPACE latest;
CREATE KEYSPACE latest WITH replication = {
'class': 'SimpleStrategy',
'replication_factor' : 1
};
USE latest;
CREATE TABLE time_series (
userid text,
pkid text,
colname map<text, text>,
PRIMARY KEY (userid, pkid)
);
UPDATE time_series SET colname = colname + {'200':'Col-Name-1'} WHERE
userid = 'XYZ' AND pkid = '1000';
UPDATE time_series SET colname = colname +
{'201':'Col-Name-2'} WHERE userid = 'XYZ' AND pkid = '1001';
UPDATE time_series SET colname = colname +
{'202':'Col-Name-3'} WHERE userid = 'XYZ' AND pkid = '1000';
UPDATE time_series SET colname = colname +
{'203':'Col-Name-4'} WHERE userid = 'XYZ' AND pkid = '1000';
UPDATE time_series SET colname = colname +
{'204':'Col-Name-5'} WHERE userid = 'XYZ' AND pkid = '1002';
SELECT * FROM time_series WHERE userid = 'XYZ';
-- returns:
-- userid | pkid | colname
----------+------+-----------------------------------------------------------------
-- XYZ | 1000 | {'200': 'Col-Name-1', '202': 'Col-Name-3', '203':
'Col-Name-4'}
-- XYZ | 1001 | {'201':
'Col-Name-2'}
-- XYZ | 1002 | {'204':
'Col-Name-5'}
-- use an app to pop off the latest key/value from the map for each row,
then sort by key desc.
On Tue, Sep 10, 2013 at 9:21 AM, Ravikumar Govindarajan <
[email protected]> wrote:
> I have been faced with a problem of grouping composites on the second-part.
>
> Lets say my CF contains this
>
>
> TimeSeriesCF
> key: UserID
> composite-col-name: TimeUUID:PKID
>
> Some sample data
>
> UserID = XYZ
> Time:PKID
> Col-Name1 = 200:1000
> Col-Name2 = 201:1001
> Col-Name3 = 202:1000
> Col-Name4 = 203:1000
> Col-Name5 = 204:1002
>
> Whenever a time-series query is issued, it should return the following in
> time-desc order.
>
> UserID = XYZ
> Col-Name5 = 204:1002
> Col-Name4 = 203:1000
> Col-Name2 = 201:1001
>
> Is something like this possible in Cassandra? Is there a different way to
> design and achieve the same objective?
>
> --
> Ravi
>
>