CAS with CQL in Cassandra
<p>I'm trying to model some time series data in Cassandra which I had been able to do with the older thrift client but CQL seems to be throwing me off. </p>

<p>I want to add a NEW column to my row IF a specific column value matches. </p>

<p>My table definition is:</p>

<pre><code>CREATE TABLE TestTable (
   key int,
   base uuid,
   ts int,                   // Timestamp (column name)
   val text,                 // Timestamp value (column value)
   PRIMARY KEY (key, ts)
) WITH CLUSTERING ORDER BY (ts DESC);
</code></pre>

<p>What I'm guessing it'd look like is:</p>

<pre><code>Row | UUID | TS  | TS | TS
--- | ---- | --- | ---| ---
 1  | id1  |  1  |  2 |  3
--- | ---  | --- | ---| ---
 2  | id2  |  1  |  5 |  6
</code></pre>

<p>So essentially, I can have a bunch of Timestamps for a given row and a SINGLE UUID for a row. 
The UUID needs to be updated for each new insert of a TS column. </p>

<p>So inserts in a row work just fine:</p>

<pre><code>insert into TestTable(key, base, ts, val) values (1, dfb63886-91a4-11e6-ae22-56b6b6499611, 50, 'one')
</code></pre>

<p>But I'm failing to figure out a way, using CQL, to INSERT a new column in a row using Cassandra transactions (CAS).</p>

<p>This one fails: </p>

<pre><code>insert into TestTable(key, base, ts, val) values (1, dfb63886-91a4-11e6-ae22-56b6b6499611, 70, 'four') if base = dfb63886-91a4-11e6-ae22-56b6b6499611;
</code></pre>

<p>with the error: </p>

<pre><code>SyntaxException: &lt;ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:106 mismatched input 'base' expecting K_NOT (..., 70, 'four') if [base] =...)"&gt;
</code></pre>

<p>And the query: </p>

<pre><code>update TestTable set val = 'four', ts=70  where key = 1 if base = dfb63886-91a4-11e6-ae22-56b6b6499611;
</code></pre>

<p>fails with the error: </p>

<pre><code>InvalidRequest: code=2200 [Invalid query] message="PRIMARY KEY part ts found in SET part"
</code></pre>

<p>I'm trying to figure out how to model the data properly so that I only have one UUID per row and can have multiple columns without having to explicitly define them during table creation, since it can vary quite a bit.</p>

<p>IIRC, it was easy doing this with the thrift client but using that isn't an option =/</p>