Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
结合IF EXISTS的Cassandra条件更新_Cassandra_Cql_Conditional Operator - Fatal编程技术网

结合IF EXISTS的Cassandra条件更新

结合IF EXISTS的Cassandra条件更新,cassandra,cql,conditional-operator,Cassandra,Cql,Conditional Operator,我知道可以在cassandra中使用条件更新(轻量级事务) update myTable set col1 = 'abc', where id = 1 IF priority < 2 更新myTable 设置 col1='abc', 其中id=1 如果优先级

我知道可以在cassandra中使用条件更新(轻量级事务)

update myTable 
set 
col1 = 'abc',
where id = 1 
IF priority < 2  
更新myTable
设置
col1='abc',
其中id=1
如果优先级<2
这允许我只更新优先级更高的行。不幸的是,当该行不存在时,该语句返回false。是否可以将“如果不存在”和“如果”与OR操作结合起来


否则,我必须对集群执行更多查询。在我的用例中,这可能是一个很大的性能问题。

我已经解决了这个问题——不幸的是,在cassandra中这是不可能的。我们必须将insert语句和update语句分开

插入。。。如果不存在
更新。。。如果优先级<2

您可以使用IN运算符,假设“优先级”有一个有限(可能很小)的允许值集,例如0和1。通过向集合中添加NULL值,如果行不存在,查询也将成功

您使用的是单个查询,但请注意,性能影响不容忽视,可能与使用两个查询相同或更糟

update myTable 
set 
col1 = 'abc',
where id = 1 
IF priority IN (0, 1, NULL)
update myTable 
set 
col1 = 'abc',
where id = 1 
IF priority IN (0, 1, NULL)