How to copy datas from one table to another table with different Schemas? (Cassandra)

Viewed 54

I have a table named table1 which includes the following

    +----------+-------+
    |date      |count  |
    +----------+-------+
    |2022-01-07|2      |
    |2022-01-06|0      |
    |2022-01-05|1      |
    +----------+-------+

Now I need to copy this table(table1) and paste this into a new table(table2) with a different schema. The new table should look like this

    +----+----------+-------+
    |type|date      |count  |
    +----+----------+-------+
    |Typ1|2022-01-07|2      |
    |Typ1|2022-01-06|0      |
    |Typ1|2022-01-05|1      |
    +----+----------+-------+

Now the problems are:

  1. I cannot use cqlsh COPY command as the scheme of both the tables is different.
  2. I cannot manually add the data to table2 because the table1 has 1000s of rows

The schema of the tables are:

Table1:

CREATE TABLE table1(
    date date PRIMARY KEY,
    count bigint
);

Table2:

CREATE TABLE table2(
    type text,
    date date ,
    count bigint,
    PRIMARY KEY(type, date)
);
1 Answers

You want to populate data of one table into another table. You can write a utility to do this. This utility will read your first table and push data into another table. If you can use spark, then you can do it pretty fast.

Related