How to migrate existing columns data to new column in Cassandra database?

198 Views Asked by At

I need to save user's quiz completion status to a Cassandra's table, previously table was designed only to hold one quiz status so I can't save if the user takes another quiz(User id is primary key). I am trying to achieve this by adding new column but don't know how to migrate current data to the new column.

id  | quiz_completed | quiz_skipped
-----+----------------+-------------
 123 |           True |        False 

With new column

id  | quiz_completed | quiz_skipped | quiz_status
-----+----------------+--------------+-----------------------------------------------------------
 123 |           True |        False | {"XXXX": {"quiz_completed": true, "quiz_skipped": false}, "YYYY": {"quiz_completed": true, "quiz_skipped": false}}

Could you please guide me on data migration?

Thanks in advance!

1

There are 1 best solutions below

1
Alex Ott On

You can use external tools to perform this, for example:

  1. Spark with Spark Cassandra Connector - in this case you can perform all operations inside the same program (if it's one-time operation, then you can do everything in the spark shell);
  2. Use some tool, like, DataStax Bulk Loader (DSBulk) to unload data into files, like CSV or JSON files, transform them with some tool (sed/awk/...), and load back.