cassandra - 与 Cassandra 数据建模相关
问题描述
要求:表在 Cassandra 中。我们需要下表中从未成功完成的作业的部分编号:
CREATE TABLE SAMPLE.ALERTS (job_id UUID, section text, result text, PRIMARY KEY(job_id,section));
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0100','successful');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0100','successful');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0200','successful');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0200','failed');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0300','failed');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0300','successful');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0400','failed');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0400','failed');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0700','failed');
INSERT INTO SAMPLE.ALERTS (job_id, section, result) values (now(),'0700','failed');
所以在输出中我们想要节号 0400 和 0700。无论如何我们可以通过改变表的结构和通过查询来实现它吗?
解决方案
通常,此类事情是通过添加物化视图或二级索引来完成的,但在您的情况下,这不是最佳选择,因为您没有很多不同的result
值......
如果您使用 DSE,那么您可以使用 DSE 搜索来执行此类查询(但要考虑到此类查询的延迟将高于普通 Cassandra 查询)。
另一种可能性 - 只需添加第二个表,您将只写入失败的请求(作为原始数据的副本)。
推荐阅读
- python - Pandas:如何仅删除列末尾的最后一个连字符
- google-forms - 如何根据其他用户过去的回复使 Google 表单自动填充?
- c - 我知道一个地址,但我应该如何判断在哪个部分?使用C的全局区域或堆区域或堆栈区域
- json - 如何解决“手势 RangeError(索引)捕获的异常:无效值:有效值范围为空:0”
- c++ - 什么会使多边形算法中的点仅在正向和反向运行时才能正常工作?
- php - PHP:如何使用键->值对每两个分隔符将一个字符串分解为一个数组
- kubernetes - 将 GKE 集群拆除为“全新”状态而不删除它?
- scala - Spark——自定义reduce函数保存到磁盘然后上传到s3
- javascript - XMLHttpRequest 返回事件对象而不是实际数据
- fortran - Fortran 将未知大小的文件读入数组