Cassandra - 带有我要更新的列的主键

Cassandra - Primary key with column which I want to update

我需要在 Cassandra 中构建 table 来存储操作状态。 我的模型如下所示:

import 1.. * import_statuses

table 导入:

id - 1
date - 2016-08-09

table import_statuses:

id - 232
import_id - 1
status - IMPORT

现在我必须在第二个 table 中搜索导入和状态。但我只需要第二个 table.

的最后状态

这两个 table 中的非规范化数据:

1, 2016-08-09, 232, 1 IMPORT
1, 2016-08-09, 233, 1 SENDING
1, 2016-08-09, 234, 1 SENT
2, 2016-08-11, 235, 2 IMPORT
2, 2016-08-11, 236, 2 SENDING

我只需要获取第三行和第五行:

1, 2016-08-09, 234, 1 SENT
2, 2016-08-11, 236, 2 SENDING

我将创建以下两个 tables,并将更新两者:

CREATE TABLE import (
  id int,
  status_id int,
  date date static,
  status text,
  PRIMARY KEY (id, status_id)
) WITH CLUSTERING ORDER BY (status_id DESC);

CREATE TABLE last_import_status (
  id int PRIMARY KEY,
  date date, 
  status_id int,
  status text
);

第一个包含非规范化数据,但由于日期字段是静态的,因此每次导入只存储一次。状态记录按降序存储 - 我知道这是一个递增的数字。如果 status_id 不是一个不断增加的数字,您可以添加一个 timeuuid 字段,并将其用作聚类键(PRIMARY KEY 中的第二个字段)。

last_import_status table 将包含每次导入的记录,status_id 和状态字段将始终包含最后一个值。