delete multiple elements from a MAP in cassandra?
Asked Answered
L

2

5

I have a field cat_to_pub with type as MAP.

{1: '9-20-21', 2: '2-5-21', 4: '2-5-21', 5: '2', 6: '2', 9: '2-83-153-149', 11: '2-5-21-31', 29: '100', 32: '113-198-21'}

I can delete an individual element from this MAP by using

DELETE cat_to_pub[1] FROM user_preferences  WHERE user_id = 'jayeshjain';

How do I remove multiple elements from this set?

for example.if I want to remove key 1 and 2,how do I form my query?

Linderman answered 7/5, 2015 at 14:4 Comment(0)
C
6

With newer version of cassandra (tried with 3.7) you could update user_preference set cat_to_pub = cat_to_pub - { 1, 2 } where user_id = 'jayeshjain';

Caucus answered 1/9, 2016 at 2:0 Comment(0)
F
3

I don't think there is a way of doing it as a single simple statement, but you should be able to do it as a batch statement. Since you are deleting from the same partition (because you are deleting from the same map column), the performance should still be pretty good as this will still be done as one operation (verified by doing a query trace).

BEGIN UNLOGGED BATCH
    DELETE cat_to_pub[1] from user_preferences where user_id ='jayeshjain';
    DELETE cat_to_pub[2] from user_preferences where user_id ='jayeshjain';
APPLY BATCH;
Fashoda answered 7/5, 2015 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.