Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

eltang avatar image
eltang asked ·

Are the CONTAINS and CONTAINS KEY operators not allowed in LWT condition?

It seems that I cannot use contains to check if a set contains an element in a LWT.

cqlsh> UPDATE users SET primary_email = 'me@gmail.com' WHERE user_id = cb6995ea-b83c-11ea-b748-acde48001122 IF linked_emails CONTAINS 'me@gmail.com';
An error occurred on line 1:
line 1:118 no viable alternative at input 'CONTAINS' (...user_id = cb6995ea-b83c-11ea-b748- acde48001122 if linked_emails [CONTAINS]...)
Interestingly, I was able to achieve the effect I wanted by changing linked_emails from a set<text> to a map<text, boolean> with only true values and changing the condition to if linked_emails['me@gmail.com'] = true. This way, if the key doesn’t exist, null is returned and the condition will be false.

This is basically the same as contains key and contains, so what is the reason this workaround is needed?
collectionslightweight transactions
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

There in no support yet for CONTAINS and CONTAINS KEY operators with lightweight transactions (LWT).

There is an open feature request for it (CASSANDRA-10537) but it hasn't been implemented yet. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.