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( ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.DefaultResultSetFuture.onSet( ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.RequestHandler.setFinalResult( ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.RequestHandler.onSet( ~[cassandra-driver-core-2.1.5.jar:na]
at com.datastax.driver.core.Connection$Dispatcher.messageReceived( ~[cassandra-driver-core-2.1.5.jar:na]
at ~[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.