c# - Cassandra 更新 - 带有时间戳聚类键的“位置”
问题描述
我在 cassandra 中有一张表,其结构如下:
CREATE TABLE answers (
Id uuid,
Name text,
Description text,
LastVersion boolean,
CreationDate timestamp,
EditionDate timestamp,
PRIMARY KEY(Id, EditionDate)
)WITH CLUSTERING ORDER BY (EditionDate DESC);
问题是当我需要将LastVersion
列的值更新为false
. 在这种情况下,仅插入新行的值Primary Key (Id, EditionDate)
+LastVersion
列的值。
按此顺序:
插入:
insert into answers
(id, name, description, lastversion, creationdate, editiondate)
values
(uuid(), 'Test 1', 'Description 1', true, dateof(now()), dateof(now()));
结果:
id | editiondate | creationdate | description | lastversion | name
--------------------------------------+---------------------------------+---------------------------------+---------------+-------------+--------
ac4f9ec1-8737-427c-8a63-7bdb62c93932 | 2018-08-01 19:54:51.603000+0000 | 2018-08-01 19:54:51.603000+0000 | Description 1 | True | Test 1
更新:
update answers
set lastversion = false
where id = ac4f9ec1-8737-427c-8a63-7bdb62c93932
and editiondate = '2018-08-01 19:54:51';
结果:
id | editiondate | creationdate | description | lastversion | name
--------------------------------------+---------------------------------+---------------------------------+---------------+-------------+--------
ac4f9ec1-8737-427c-8a63-7bdb62c93932 | 2018-08-01 19:54:51.603000+0000 | 2018-08-01 19:54:51.603000+0000 | Description 1 | True | Test 1
ac4f9ec1-8737-427c-8a63-7bdb62c93932 | 2018-08-01 19:54:51.000000+0000 | null | null | False | null
怎么了?实际上,该EditionTime
字段似乎有所不同,但是我在UPDATE
查询上花费了相同的值。
解决方案
您的更新使用的值editionDate
与您插入的值不同,因此您的更新找不到原始行。Cassandra 的更新和插入确实是 upsert,因此正在插入带有新键的新行。
请注意,EditionDate 具有毫秒精度,但您的更新仅将其指定为最接近的秒数。
推荐阅读
- svg - 为什么 viewBox 会影响我的非缩放笔画?
- lua - 在LUA(Corona SDK)中比较第一次点击的价值和第二次点击的价值
- vue.js - Vue
在孩子里面 组件不更新父组件 - azure - 替换 Azure 资源组中不同资源的一个标记
- javascript - 如何从 HTML 中的 md-switch 存储和修改 JS 变量?
- python - Selenium click() 函数(看似)随机不点击框[无错误][Python]
- linux - 如何知道使用 gdb 的程序中的库调用生成了哪些系统调用?
- go - 我在哪里将我自己的包的代码放在 Golang 中
- python - 调整单个子图宽度的简单方法?
- javascript - 错误:A
可能只有一个子元素。包含开关,之前使用此代码