Unable to remove key\value pair from map column in cassandra

653 views
Skip to first unread message

hemabs

unread,
Oct 20, 2014, 2:55:50 PM10/20/14
to java-dri...@lists.datastax.com
Hi,

From the link below:

I am able to figure out add and remove for list and set:
Set: addAll, removeAll
List: appendAll, discardAll
Map: putAll

What is the equivalent remove method for a map to remove key/value pair from the map column.

Is this not provided by the Cassandra API?

Thanks

Olivier Michallat

unread,
Oct 21, 2014, 3:35:24 AM10/21/14
to java-dri...@lists.datastax.com
Hi,

The CQL syntax to delete from a map is:

    DELETE m['key'] FROM foo WHERE k=1

The equivalent with QueryBuilder is:

    delete().mapElt("m", "key").from("foo").where(eq("k", 1));

--

Olivier Michallat

Driver & tools engineer, DataStax


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

hemabs

unread,
Oct 21, 2014, 1:58:03 PM10/21/14
to java-dri...@lists.datastax.com
Thanks Olivier. Is there any other way of doing it? I did not wanted to use the raw delete statement or QueryBuilder that uses delete function.

Olivier Michallat

unread,
Oct 22, 2014, 11:19:47 AM10/22/14
to java-dri...@lists.datastax.com
Not that I'm aware of. Maps don't support the "delete with update" syntax that sets have (UPDATE foo  SET s = s - {e} ...). I don't know if there's a good reason for that, you can ask on the Cassandra user mailing list if you want more details.

--

Olivier Michallat

Driver & tools engineer, DataStax


hemabs

unread,
Oct 23, 2014, 12:40:11 AM10/23/14
to java-dri...@lists.datastax.com
Thank you Olivier. Appreciate it.

DuyHai Doan

unread,
Oct 23, 2014, 11:05:28 AM10/23/14
to java-dri...@lists.datastax.com
Or you can do

UPDATE  foo SET m['key'] = null WHERE k=1

Setting null means deleting in CQL, at least for now, it may change in the future

hemabs

unread,
Oct 28, 2014, 2:41:01 PM10/28/14
to java-dri...@lists.datastax.com
Thanks DuyHai for the help.
Reply all
Reply to author
Forward
0 new messages