1
votes

I have Cassandra cluster ( 2 nodes ) and i trying to alter value column type to Map.

After executing ALTER TABLE "keyspace"."table" ALTER value TYPE Map; in cqlsh i got an error that modifying not allowed. (Table is empty)

CREATE TABLE "keyspace"."table" (
    key text,
    column1 bigint,
    column2 bigint,
    value text,
    PRIMARY KEY (key, column1, column2)
) WITH COMPACT STORAGE
    AND CLUSTERING ORDER BY (column1 ASC, column2 ASC)
    AND bloom_filter_fp_chance = 0.1
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.SnappyCompressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.05
    AND default_time_to_live = 0
    AND gc_grace_seconds = 5
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

[cqlsh 5.0.1 | Cassandra 3.11.0 | CQL spec 3.4.4 | Native protocol v4]

Is it possible to alter table for this table structure? What can cause this issue?

Thanks

2

2 Answers

1
votes

That kind of alteration is unfortunately not supported in Cassandra. For a reference regarding CQL data types and supported conversions, please see the Datastax documentation.

I don't know if this will work, but you could try deleting the column and then create it again?

0
votes

Unfortunately, dropping and re-adding the column only works in certain cases where the types involved are similar in nature.

Bigger changes, for example changing from an int to a boolean will produce an error along the lines of:

code=2200 [Invalid query] message="Cannot re-add previously dropped column 'MYCOLUMN' of type boolean, incompatible with previous type int"

If the table in question is part of a new development effort and has not been released into production, you might be better off dropping the table and re-adding it the new type.