来自不同 table 的 Cassandra If 子句条件
Cassandra If clause conditon from different table
我必须在 shopping_cart table 中更新/插入数据,只有当 cassandra 中的库存 table 中存在一些数量时,这需要是原子操作,因为库存 table 经常更新,我正在尝试使用如下所示的轻量级交易
update shopping_cart
set
quantity=1
where
item='item1'
if
(select quantity from inventory where item='item1') = 2;
但我收到一个错误
mismatch input '(' expecting K_NOT
可能轻量级事务不是执行此操作的最佳方法我也认为 if 子句不支持来自 cassandra 中不同 table 的查询。
那么在不影响原子性的情况下,在 cassandra 中实现上述操作的最佳方法是什么。
以上类型的查询是不可能的 - 我能想到的两个选项,
- 将数量保留在 shopping_cart table 中,当您想更新数量时,使用批处理语句在两个 table 中更新。
- 在应用程序本身中处理这个问题,但会更痛苦。
我必须在 shopping_cart table 中更新/插入数据,只有当 cassandra 中的库存 table 中存在一些数量时,这需要是原子操作,因为库存 table 经常更新,我正在尝试使用如下所示的轻量级交易
update shopping_cart
set
quantity=1
where
item='item1'
if
(select quantity from inventory where item='item1') = 2;
但我收到一个错误
mismatch input '(' expecting K_NOT
可能轻量级事务不是执行此操作的最佳方法我也认为 if 子句不支持来自 cassandra 中不同 table 的查询。
那么在不影响原子性的情况下,在 cassandra 中实现上述操作的最佳方法是什么。
以上类型的查询是不可能的 - 我能想到的两个选项,
- 将数量保留在 shopping_cart table 中,当您想更新数量时,使用批处理语句在两个 table 中更新。
- 在应用程序本身中处理这个问题,但会更痛苦。