Cassandra: Adding new column to the table

邮差的信 提交于 2019-12-06 02:20:30

You're running into CASSANDRA-6276. The problem is when you drop a column in Cassandra that the data in that column doesn't just disappear, and Cassandra may attempt to read that data with its new comparator type.

From the linked JIRA ticket:

Unfortunately, we can't allow dropping a component from the comparator, including dropping individual collection columns from ColumnToCollectionType. If we do allow that, and have pre-existing data of that type, C* simply wouldn't know how to compare those...

...even if we did, and allowed [users] to create a different collection with the same name, we'd hit a different issue: the new collection's comparator would be used to compare potentially incompatible types.

The JIRA suggests that this may not be an issue in Cassandra 3.x, but I just tried it in 3.0.3 and it fails with the same error.

What did I do wrong? I am pretty new to Cassandra. Any suggestions?

Unfortunately, the only way around this one is to use a different name for your new list.

EDIT: I've tried this out in Cassandra and ended up with inconsistent missing data. Best way to proceed is to change the column name as suggested in CASSANDRA-6276. And always follow documentation guidelines :)

-WARNING- According to this comment from CASSANDRA-6276, running the following workaround is unsafe.

Elaborating on @masum's comment - it's possible to work around the limitation by first recreating the column with a non-collection type such as an int. Afterwards, you can drop and recreate again using the new collection type.

From your example, assuming we have a business_sys set:

ALTER TABLE my_table ADD business_sys set<text>;
ALTER TABLE my_table DROP business_sys;

Now re-add the column as int and drop it again:

ALTER TABLE my_table ADD business_sys int;
ALTER TABLE my_table DROP business_sys;

Finally, you can re-create the column with the same name but different collection type:

ALTER TABLE my_table ADD business_sys list<text>;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!