PLANNED MAINTENANCE

Hello, DataStax Community!

We want to make you aware of a few operational updates which will be carried out on the site. We are working hard to streamline the login process to integrate with other DataStax resources. As such, you will soon be prompted to update your password. Please note that your username will remain the same.

As we work to improve your user experience, please be aware that login to the DataStax Community will be unavailable for a few hours on:

  • Wednesday, July 15 16:00 PDT | 19:00 EDT | 20:00 BRT
  • Thursday, July 16 00:00 BST | 01:00 CEST | 04:30 IST | 07:00 CST | 09:00 AEST

For more info, check out the FAQ page. Thank you for being a valued member of our community.


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.