CQL--通过id和最新时间​​戳获取记录

CQL--get records by id and latest timestamp

我是 cassandra 的新手,所以这听起来像是一个新手问题。 我是运行 cqlsh 5.0.1 |本地的 Cassandra 2.1.4。

我有一个 table 如下所示:

CREATE TABLE master (
id uuid,
creation timestamp,
event_type text,
name text,
PRIMARY KEY(id,creation)
);

...记录为:

id                                   | creation                 | event_type | name
--------------------------------------+--------------------------+------------+------------------
 305abd6d-34b8-4f36-96c6-9ea0c11be952 | 2015-04-15 14:01:54-0400 |     create |            test2
 305abd6d-34b8-4f36-96c6-9ea0c11be952 | 2015-04-15 14:03:03-0400 |     update |     test2 update
 7440c51c-6441-44fb-833b-6140fbe822eb | 2015-04-15 14:01:54-0400 |     create |            test3
 7440c51c-6441-44fb-833b-6140fbe822eb | 2015-04-15 14:03:44-0400 |     update |     test3 update
 7440c51c-6441-44fb-833b-6140fbe822eb | 2015-04-15 14:04:34-0400 |     update | test3 2nd update

 bf42a120-dec1-47d8-bde2-c0d76f1c93a5 | 2015-04-15 14:01:54-0400 |     create |            test1

我如何 select 所有具有不同 ID 和最后修改时间戳的记录。 结果应该是这样的:

305abd6d-34b8-4f36-96c6-9ea0c11be952 | 2015-04-15 14:03:03-0400 |     update |     test2 update
 7440c51c-6441-44fb-833b-6140fbe822eb | 2015-04-15 14:04:34-0400 |     update | test3 2nd update
 bf42a120-dec1-47d8-bde2-c0d76f1c93a5 | 2015-04-15 14:01:54-0400 |     create |            test1

鉴于您当前的结构,您将无法使用 DISTINCT 查询 select 除 id 之外的任何其他列。您可以创建另一个查询 table,仅使用 id 作为 PK,然后 运行 一个基本的 SELECT(它应该始终保持最后修改日期)

CREATE TABLE querytable (
    id uuid,
    creation timestamp,
    event_type text,
    name text,
    PRIMARY KEY(id)
);

SELECT * from querytable --should only contain unique ID's and the last updated creation date.

你必须更新此 table,同时更新母版。