Cassandra alter column type: which types are compatible?
Asked Answered
S

2

5

There's some patchy information on the interwebs about some examples when column type can't be changed. For example, on the DataStax site there's a mention:

  • Changing the type of a clustering column.
  • Changing columns on which an index is defined.

Or, for example, here is mentioned that you can't convert uuid to timeuuid. And from my personal experience, I can't change text to timestamp (we store dates in ISO8601 format as text, an unfortunate decision early in the project timeline).

However, I can't find a full description of which types can be converted to which, or at least which types can't be converted to which. Does anyone know?

Spadiceous answered 7/8, 2015 at 14:37 Comment(1)
I found this link from DataStax for version 3.Spunk
W
7

Great question! I have to admit that I was a bit surprised at the lack of thorough documentation on this one, as well. Your question inspired me to do a little investigation and blog about it as well.

Essentially, here is a comprehensive list of Cassandra compatible CQL types (using Cassandra 2.2.0):

  • ascii -> blob, text, varchar
  • bigint -> blob, timestamp, varint
  • int -> blob, varint
  • text -> blob, varchar
  • timestamp -> bigint, blob, varint
  • timeuuid -> blob, UUID
  • varchar -> blob, text

Notes:

  • blob is in there a lot, because anything can be converted to a blob.
  • cqlsh allows you to convert a varint to the new date type, but this is a bug (CASSANDRA-10027). Don't actually try that.
Washtub answered 9/8, 2015 at 16:36 Comment(2)
I am surprised to know that one can't change any type to collection of that type. For e.q changing text to List<text>.Teodorateodorico
bigint -> timestamp causes an error "Altering of types is not allowed" in CQLSH 5 and Cassandra 3.11Modulate
T
3

The 2020 answer:

This functionality seems to have been completely removed. The version 6.8 documentation states:

Cannot change the data type of a column.

Titanesque answered 20/4, 2020 at 11:2 Comment(1)
It's removed started with Cassandra 3.0 (DSE 5.0)Cleotildeclepe

© 2022 - 2024 — McMap. All rights reserved.