[ 
https://issues.apache.org/jira/browse/CASSANDRA-20680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17954472#comment-17954472
 ] 

David Capwell commented on CASSANDRA-20680:
-------------------------------------------

bq. Why is a batch statement with two IF EXISTS statement allowed, while the 
one mixing IF EXISTS and IF r > 0 is not? I thought that the Invalid query 
error should be returned only for conditions that cannot be met (e.g., asking 
for the same row to EXISTS and NOT EXISTS in the same time).

That is partially an implementation detail.  The logic assumes that no row has 
multiple conditions, and you are adding multiple conditions to a row.  >From a 
semantic point of view there isn't anything wrong with your query, but it's 
just not currently supported.

Now, if you change your query to touch 2 different rows, then it should work 
(assuming its the same partition)

> Cannot mix IF conditions and IF NOT EXISTS for the same row, even though the 
> conditions could be met
> ----------------------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-20680
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-20680
>             Project: Apache Cassandra
>          Issue Type: Improvement
>          Components: Feature/Lightweight Transactions
>            Reporter: Andrzej Jackowski
>            Priority: Normal
>
> Mixing {_}IF conditions{_}, {_}IF EXISTS{_}, and _IF NOT EXISTS_ for the same 
> row is never possible, even in batches for which all LWT conditions are true.
>  
> Consider the following example:
> {noformat}
> CREATE KEYSPACE ks WITH replication =    {'class': 'NetworkTopologyStrategy', 
> 'replication_factor' : 1};
> CREATE TABLE ks.cf (p int, c int, r int, PRIMARY KEY(p, c));
> INSERT INTO ks.cf (p,c,r) VALUES (1,1,1);
>    
> BEGIN BATCH
>   UPDATE ks.cf SET r=2 WHERE p=1 AND c=1 IF EXISTS
>   UPDATE ks.cf SET r=3 WHERE p=1 AND c=1 IF r > 0
> APPLY BATCH; {noformat}
> Both _IF EXISTS_ and _IF r > 0_  conditions are true, however Cassandra 
> rejects the batch with the following error:
> {noformat}
> "Cannot mix IF conditions and IF NOT EXISTS for the same row" {noformat}
>  
> In contrast, a very similar batch with two _IF EXISTS_ conditions works:
> {noformat}
> BEGIN BATCH
>   UPDATE ks.cf SET r=2 WHERE p=1 AND c=1 IF EXISTS
>   UPDATE ks.cf SET r=3 WHERE p=1 AND c=1 IF EXISTS
> APPLY BATCH;
>    
> [applied]
> -----------
>   True{noformat}
>  
> I can see two problems here:
>  # The error message is incorrect: there is no _NOT EXISTS_ in my query. 
> However, it is rather a cosmetic issue.
>  # Why is a batch statement with two _IF EXISTS_ statement allowed, while the 
> one mixing _IF EXISTS_ and _IF r > 0_ is not? I thought that the _Invalid 
> query_ error should be returned only for conditions that cannot be met (e.g., 
> asking for the same row to _EXISTS_ and _NOT EXISTS_ in the same time).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to