Cassandra Errors: The UnSet Upsert

During a late night coding session I got the following trace from the Datastax Cassandra Java Driver:

com.datastax.driver.core.exceptions.SyntaxError: line 1:36 mismatched input 'WHERE' expecting K_SET (UPDATE my_table [WHERE] id...)
at com.datastax.driver.core.Responses$Error.asException(Responses.java:101) ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:140) ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:293) ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.RequestHandler.onSet(RequestHandler.java:455) ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.Connection$Dispatcher.messageReceived(Connection.java:734) ~[cassandra-driver-core-2.1.5.jar:na]
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) ~[netty-3.10.1.Final.jar:na]

Ok. Let’s think it through:

  • Did we not put a key column in the WHERE clause? Nope.
  • Did we put a non-key column in the WHERE clause? Nope.
  • Did we put a key column in the SET clause? Nope.

OK, what then?

Well… my code has many setIfNonNull(...) helpers. Turns out my testing dataset had all NULLs. Thus, nothing was being set! Obviously an UPDATE must update something (though the lines are blurred in C* Upsert land).

So, this cryptic message from C* should really read “Update statement missing SET clause, you fool.” Now if I could find it in the source, I’d submit a PR.