cassandradatastax-java-driver

How do you add elements to a set with DataStax QueryBuilder?


I have a table whose column types are

text, bigint, set<text> 

I'm trying to update a single row and add an element to the set using QueryBuilder.

The code that overwrites the existing set looks like this (note this is scala):

val query = QueryBuilder.update("twitter", "tweets")
  .`with`(QueryBuilder.set("sinceid", update.sinceID))
  .and(QueryBuilder.set("tweets", setAsJavaSet(update.tweets)))
  .where(QueryBuilder.eq("handle", update.handle))

I was able to find the actual CQL for adding an element to a set which is:

UPDATE users
SET emails = emails + {'fb@friendsofmordor.org'} WHERE user_id = 'frodo';

But could not find an example using QueryBuilder.

Based off of the CQL I also tried:

  .and(QueryBuilder.set("tweets", "tweets"+{setAsJavaSet(update.tweets)}))

But it did not work. Thanks in advance


Solution

  • Use add (add one element at a time) or addAll (more than one any number of element at a time) method to add to a set.