Search code examples
cassandradatastax-java-driver

Datastax java-driver QueryBuilder.update issue in scala


Here is the scala code I am attempting to use to update a row in a cassandra database:

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

which is based off of the suggestion here

Everything seems to work correctly except for the ".and". The error I get back is

value and is not a member of com.datastax.driver.core.querybuilder.Assignment

Which, of course, is true, but at that point in the statement it should be using

com.datastax.driver.core.querybuilder.Update.Conditions

Which contains the and()

Thank you for your help


Solution

  • I think you have your parentheses mismatched, you are getting the error because and is not a member of Assignment which is what QueryBuilder.set("sinceid", update.sinceId) returns. You need to add an extra parentheses after sinceId) so the .and chains off of .with which returns Assignments which has an and method.

    The following works for me:

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