Search code examples
cassandracql

Cassandra iterate over elements of set


I need to move data from one table to another, but tables definition is a bit different:

CREATE TABLE elements (
    id timeuuid PRIMARY KEY,
    other_ids set<text>,
    name text
) 

CREATE TABLE elements_new (
    id text PRIMARY KEY,
    other_id text,
    name text
)

I need to create a row in new table for each set element of old table.

How to iterate over elements of set in cql statement? I couldn't find any documentation on this.


Solution

  • You can do this only by programming - there is no support for this in CQL.

    Depending on the amount of data you may need either to use Spark Cassandra connector, or write your code that will go through all token ranges, fetch data & rework them into new structure.