我正在尝试为用户的历史流建模...像推特一样思考,每条记录都有三列:
userid, posted_time, message
如果我的主要用例是从 所有 用户检索最新推文。有什么简单的方法可以在Cassandra中对此进行建模吗?
在sql中,它将是
select * from t where (userid, posted_time) in (select userid, max(posted_time) from t group by userid);
但我认为在卡桑德拉是不可能的。
答案 0 :(得分:0)
对于Cassandra,您必须对数据进行非规范化,以便您希望执行的查询有效。因此,如果要查找用户最新更新的时间,则应该有一个表,其中包含用户ID作为其密钥,最新更新的时间作为值。
答案 1 :(得分:0)
Create table tblname(userid varchar,
posted_time timeuuid,
message text,
primary key(userid,posted_time)
)with clustering order by (posted_time desc);
遵循架构
Select * from tblname where userid='id' limit 1
将为每个用户提供最新记录 您也可以通过posting_time
订购结果