0
votes

I have a large table in Cassandra with a column of type int but no values are outside the range 0-10. I want to reduce the table size by changing the type of the column to tinyint.

This is the error I get

[Query invalid because of configuration issue] message="Cannot change COLUMN_NAME from type int to type tinyint: types are not order-compatible.">

Is there a nice way to handle this with a cast or other such query trickery?

If not ... and without taking the database down, is there a better way to solve this than doing the following?

  1. make a new column of type tinyint
  2. update my code to duplicate data to this column during write operations
  3. copy old data to the new column [will take a while probably]
  4. swap the names of the columns
  5. revert my code change (only update one column)
  6. delete the old int column
1

1 Answers

0
votes

I would say deleting old columns and copying data to new columns is not ideal.

If your cassandra column family is accessed by a single entry point (service), my suggestion would be,

  1. Add a new column.
  2. Retain the old column. (You can rename it like COLUMNNAME_OBSOLETE).
  3. After updating your code, only populate the data against new column in your code.
  4. While reading data into domain object, if your new column is null then fill it with old column.

In one of our project, we followed the above steps against prod data and it worked fine. After few months, when we weren't need of COLUMNNAME_OBSOLETE we dropped that column.