Question

I have a table that stores several connections' metadata. This table have to be rebuilt after some specific events.

Is there a way to build a temporary table and replace the original one with the newer? After a Google search I found out that it is not possible to rename a table.

Does anyone have a suggestion?

Was it helpful?

Solution

If by "rebuilt", you mean you want to start from scratch with the same schema, but no data, then you can call TRUNCATE on the table and then repopulate it with new data. If you mean that you need to swap in new contents all at once, then your best bet is probably to version your table, so that you keep creating new tables ("foo_v1, foo_v2" etc). You then need to parameterize your client code to know what version they need to talk to at some point. You can track the version in another Cassandra table.

OTHER TIPS

A possible way to do this is using the COPY command (http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/copy_r.html)

So you can do the next:

  1. Copy the data of the temporary table to a csv file.

    COPY temporaryTable (field1, field2) TO 'temp.csv';

  2. Truncate the definitive table.

    TRUNCATE definitiveTable;

  3. Copy from the csv file to the defintive table.

    COPY temporaryTable (field1, field2) FROM 'temp.csv';

Anyway, probably it is better to create some method to get the data from the temporary table and iterating over the dataset write on the definitive table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top