Cassandra 聚类顺序不排序列表

Cassandra Clustering order not sorting list

我有一个病人 table 和 treatment_patient,其中 pat_id 作为外键。我想执行一个查询,使 treatment_patient 始终 returns 值按 pat_id 排序。 我尝试添加 WITH CLUSTERING ORDER BY (patid ASC);最后但没有用。

CREATE TABLE patient(
record_id uuid PRIMARY KEY,
patid int,
name text,
dob timestamp
);

插入患者:

insert into patient (record_id, patid, name, dob) values (uuid(), 123, 'John Doe', '2015-01-01 22:00');
insert into patient (record_id, patid, name, dob) values (uuid(), 456, 'Joy Smith', '2014-11-01 21:00');

Treatment_Patients table:

CREATE TABLE treatments_patients(
treatpat_uuid int,
patid int,
diagnosis text,
PRIMARY KEY(treatpat_uuid,patid)
) WITH CLUSTERING ORDER BY (patid ASC);

插入 treatment_patients;

insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (123, 011, 'Cold');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (456, 006, 'Cough');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (789, 002, 'flu');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (12, 231, 'Acne');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (789, 001, 'Allergy');

输出:

treatpat_uuid | patid | diagnosis
---------------+-------+-----------
123 |    11 |      Cold
456 |     6 |     Cough
789 |     1 |   Allergy
789 |     2 |       flu
12 |   231 |      Acne

(5 行)

Cassandra 仅在分区内进行排序。由于您的结果集包含来自多个分区 (treapat_uuid) 的行,因此您的数据不会按该级别排序。但是,它将在共享同一分区的行中排序,即 treapat_uuid 中的行按升序排序。

treatpat_uuid | patid | diagnosis
--------------+-------+-----------
...
          789 |     1 |   Allergy
          789 |     2 |       flu
...