2017-10-05 87 views
1

我想执行查询,select * from comments_by_post where post_id ='postid'; 我设计意见表如下 -cassandra评论表数据建模

CREATE TABLE comments_by_post (
    post_id text, 
    posted_timestamp timestamp, 
    actor_id text, 
    comment_id text, 
    actor_info frozen<actor>, 
    actor_type text, 
    comment text, 
    PRIMARY KEY (post_id, posted_timestamp, actor_id, comment_id) 
) WITH CLUSTERING ORDER BY (posted_timestamp DESC, actor_id ASC, comment_id ASC) 

一切顺利,但问题是当演员更新他/她的信息,我怎样才能更新actor_info然后,因为要更新我需要提供POST_ID的信息, posted_timestamp和actor_id,这对于一次更新一行信息是不可行的。什么可能是最佳表格。

回答

1

冻结值将多个组件串行化为单个值。非冻结类型允许更新到单个字段。 Cassandra将冻结类型的值视为blob。整个值必须被覆盖。

因此,当关于演员的信息被更新时,您应该在您的评论表中更新该演员的整个值。

稍后编辑:由于actor_info不会非常频繁地更新,您可以对actor_id进行选择以获取完整的主键,然后执行更新。在这之前,必须创建一个关于actor_id的二级索引

+0

问题是更新actor_info,我将不得不提供posting_timestamp,还有actor_id。 –

+0

你能为演员提供定义吗? – Horia