shehzadjahagirdar_185613 avatar image
shehzadjahagirdar_185613 asked Erick Ramirez commented

Why can't I add a dropped column with a different data type after upgrading to Cassandra 3.11.11?

We are not able to alter column of datatype decimal to text in apache cassandra 3.11.11 version.Below are the details with the trace of error.

We use below command to alter column

step 1:-Where mycol data type was of data type 'text'.

Step 2:-alter table mytable drop mycol ;

Step 3:-alter table mytable add mycol decimal;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot re-add previously dropped column 'mycol' of type decimal, incompatible with previous type text".

We were able to perform this before on apache cassandra 3.11.3 version but since we have upgraded to apache cassandra 3.11.11 we are facing the above issue while alteration.

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

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

Re-adding a column with a different data type after it has been dropped from a table is bad practice because it can lead to unexpected results particularly when data already exists in the table.

For a bit of background information, the Cassandra storage engine was completely refactored in 3.0 (CASSANDRA-8099). As part of the refactoring, the SerializationHeader class only retrieves the column names from the metadata (see SerializationHeader.toHeader() method in C* 3.0.21) and ignores the column type, i.e. regular or static. If a column's type is changed with an ALTER TABLE ... DROP then ALTER TABLE ... ADD, the header could be interpreted incorrectly and may lead to CorruptSSTableException or data corruption (CASSANDRA-14843).

There is a proposed solution to the problem I described above which involves storing additional metadata about the dropped columns but it is only planned to be implemented in a future major version of Cassandra.

Until that new solution is implemented, a workaround was implemented in C* 3.0.19+ and 3.11.5+ to prevent columns from being added back to a table after it has been dropped (CASSANDRA-14948). This improvement completely blocks DBAs from re-using column names in a table.

If you really must use the same name, I would recommend adding a suffix like "v2" so the new column name is of the form columnname_v2. Cheers!

2 comments 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.

shehzadjahagirdar_185613 avatar image shehzadjahagirdar_185613 commented ·

@Erick Ramirez Conversion of 'decimal' to 'text' is possible in Apache Cassandra 3.11.3 version because it is a valid conversion but due to vulnerabilities identified in C* 3.11.3 version we have recently upgraded to C* 3.11.11 version in which we are not able to perform conversion from 'decimal' to 'text'.I kindly request you to please suggest some workaround as we have dependencies on above conversion & need to use the same name.

0 Likes 0 ·
Erick Ramirez avatar image Erick Ramirez ♦♦ shehzadjahagirdar_185613 commented ·

That conversion is not valid so it is not allowed. There is no "magic" workaround since it's not valid. Cheers!

0 Likes 0 ·