0

I'm new to cassandra and I'm trying to create a new column witch content is based on another column.

More precisely what I want to achive is, starting with following table:

ColumnA ColumnB
1 text

I want to update the table obtaining :

ColumnA ColumnB ColumnC
1 text ColumnA value +1

I'm tryng something like this, after adding the columnC, update table set columnC = columnA+1 ; but this gave me the error

Only expressions of the form X = X - are supported.

So I tryed update table set columnC = columnA ; but even this gave me the error

no viable alternative at input ';' (update table set columnC=[columnA];)

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
  • Unfortunately, this is not possible with CQL. This is something that would have to be done in the application level. – Aaron Oct 20 '22 at 14:19

1 Answers1

0

The CQL grammar does not support this type of operation because it does not scale.

Imagine if you had billions and billions of partitions across hundreds of nodes. That kind of operation will require a full table scan. And if you had millions of concurrent users, it would be difficult to make the updates idempotent since the partitions/rows are not locked between the time that you read the value in column A and write it to column C.

You will need to write an ETL app for it, preferably in Spark so it can efficiently iterate over the partitions/rows. Cheers!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23