Search code examples
cassandracqldatabasenosql

CQL no viable alternative at input '(' error


I have a issue with my CQL and cassandra is giving me no viable alternative at input '(' (...WHERE id = ? if [(]...) error message. I think there is a problem with my statement.

UPDATE <TABLE> USING TTL 300 
  SET <attribute1> = 13381990-735b-11e5-9bed-2ae6d3dfc201
  WHERE <attribute2> = dfa2efb0-7247-11e5-a9e5-0242ac110003 
    IF (<attribute1> = null OR <attribute1> = 13381990-735b-11e5-9bed-2ae6d3dfc201) AND <attribute3> = 0; 

Any idea were the problem is in the statement about?


Solution

  • It would help to have your complete table structure, so to test your statement I made a couple of educated guesses.

    With this table:

    CREATE TABLE lwtTest (attribute1 timeuuid, attribute2 timeuuid PRIMARY KEY, attribute3 int);
    

    This statement works, as long as I don't add the lightweight transaction on the end:

    UPDATE lwttest USING TTL 300 SET attribute1=13381990-735b-11e5-9bed-2ae6d3dfc201 
    WHERE attribute2=dfa2efb0-7247-11e5-a9e5-0242ac110003;
    

    Your lightweight transaction...

    IF (attribute1=null OR attribute1=13381990-735b-11e5-9bed-2ae6d3dfc201) AND attribute3 = 0;
    

    ...has a few issues.

    • "null" in Cassandra is not similar (at all) to its RDBMS counterpart. Not every row needs to have a value for every column. Those CQL rows without values for certain column values in a table will show "null." But you cannot query by "null" since it isn't really there.
    • The OR keyword does not exist in CQL.
    • You cannot use extra parenthesis to separate conditions in your WHERE clause or your lightweight transaction.

    Bearing those points in mind, the following UPDATE and lightweight transaction runs without error:

    UPDATE lwttest USING TTL 300 SET attribute1=13381990-735b-11e5-9bed-2ae6d3dfc201 
    WHERE attribute2=dfa2efb0-7247-11e5-a9e5-0242ac110003
    IF attribute1=13381990-735b-11e5-9bed-2ae6d3dfc201 AND attribute3=0;
    
     [applied]
    -----------
         False