question

xenobius.lee_170168 avatar image
xenobius.lee_170168 asked Erick Ramirez edited

How to change or update createdate with primary key?

Dear,


We have a specail case to handle thingwox with datastax.

I just want to add measure data set into thingworx and cassandra but data include several measured data such as measured by manual and then this data should be inserted middleware database.

Thingworx take this data after updated in kepware through interanl middleware.

It means there is two types of times, one is measued time by manual and another is thingworx create time.

In this case thingworx insert measure data in storing time instead of measure time.

But customer want to see data with measure time. But thingworx insert data with created time.

We are about to change createdate but this should be primary key and cannot be changed.


How should we resolve this problem? Otherwise do we get hiw to change primary key in Cassandra?

data modeling
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

pmcfadin avatar image
pmcfadin answered

Once the primary key is created, it cannot be changed. This is due to how the data is stored and the dependency on the primary key to determine cluster placement and file layout.

If you need to change the primary key there are a couple of options, but all of them require creating a new table and migrating data. Migration can be done with a little but of code or tools like Bulk Loader. You can even use Spark in some cases.

Online migration:

  • Create the new table making sure the table name is unique and you have a new primary key
  • Alter your application code to start writing to both old and new table
  • Migrate old data into new table
  • Alter code to start reading from new table
  • Drop old table


Offline migration:

  • Export all data from old table
  • Create new table with new primary key
  • Import data in the new order
  • Alter application code to use the new table

In either case, the idempotent nature of Cassandra data will keep you from creating extra data if there is overlap when importing records.

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.