Search code examples
cassandracqlcql3cqlshcqlinq

Is Cassandra Update IF statement where the condition is an inequality expression supported?


Is UPDATE IF [condition] where [condition] is an inequality, supported by Cassandra CQL?

I had a look over the language reference and it seems that CQL should not be able to support the inequality through its grammar. I used the language reference from here: https://cassandra.apache.org/doc/cql3/CQL.html#updateStmt

What is confusing is that using the C# driver or CQLSH the query is executed successfully, but when doing the same thing from Datasax DevCenter I get an error.

I'm using a query similar to the one below:

UPDATE product
SET edit_date = [new_value]
WHERE customer_id = '4' AND code = 'AMZ-ISMDB' 
IF edit_date < [new_value]

The results are as follows:

  • Datasax DevCenter throws an error when trying to execute the script snippet. The error I get is complaining about the inequality in the UPDATE IF part of the script.

    There is one syntax error in the current script (see details below). Please fix it and try again. Line 29: no viable alternative at input '<'

  • If I use CLINQ with the Datasax C# driver the query is generated as above and when executed the update is persisted if the new edit_date is after the existing edit_date which is the expected behaviour.

  • Using CQLSH the query runs successfully and the update is persisted


Solution

  • The issue is most likely that DevCenter has not been updated to support the latest syntax.

    Inequality conditions were added in: CASSANDRA-6839

    Looks like they missed updating the docs when that was added. I open CASSANDRA-10752 to get that fixed.