Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra alter column type: which types are compatible?

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?

like image 970
Haspemulator Avatar asked Aug 07 '15 14:08

Haspemulator


People also ask

How do I change the column type in Cassandra?

Changing the data type of a column after it is defined or added to a table using ALTER TABLE. Using ALTER TABLE, you can change the data type of a column after it is defined or added to a table.

Which command modifies the column properties of a table in Cassandra?

Modifies the columns and properties of a table. Changes the datatype of a columns, add new columns, drop existing columns, renames columns, and change table properties. The command returns no results.

How many columns does Cassandra support?

Cassandra allows 2 billion columns per row.


1 Answers

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.
like image 117
Aaron Avatar answered Sep 21 '22 13:09

Aaron