在cassandra中更改列类型时出错

在cassandra中更改列类型时出错,cassandra,alter-table,cql3,datastax,Cassandra,Alter Table,Cql3,Datastax,在cassandra中更改表中列的类型时遇到问题 下面是指向的链接,该链接表示,如果列不是主键的一部分并且没有索引,则可以更改类型。我就是不能让它工作 cqlsh:test> show VERSION [cqlsh 3.1.8 | Cassandra 1.2.13 | CQL spec 3.0.0 | Thrift protocol 19.36.2] CREATE TABLE mytable ( id1 text, id2 text, col1 int, col2 b

在cassandra中更改表中列的类型时遇到问题

下面是指向的链接,该链接表示,如果列不是主键的一部分并且没有索引,则可以更改类型。我就是不能让它工作

cqlsh:test> show VERSION  
[cqlsh 3.1.8 | Cassandra 1.2.13 | CQL spec 3.0.0 | Thrift protocol 19.36.2]

CREATE TABLE mytable (
  id1 text,
  id2 text,
  col1 int,
  col2 bigint,
  col3 text,
  PRIMARY KEY (id1, id2)
) WITH CLUSTERING ORDER BY (id2 DESC);

UPDATE mytable SET col1 = 123, col2 = 1234, col3 = '12345' WHERE id1 = 'id1' AND id2 = 'id2';

SELECT * FROM mytable ;

 id1 | id2 | col1 | col2 | col3
-----+-----+------+------+-------
 id1 | id2 |  123 | 1234 | 12345
当我尝试更改列类型时,会出现错误

 ALTER TABLE mytable ALTER col1 TYPE text;
 Bad Request: Cannot change col1 from type int to type text: types are incompatible.

 ALTER TABLE mytable ALTER col1 TYPE text;
 Bad Request: Cannot change col1 from type int to type text: types are incompatible.

 ALTER TABLE mytable ALTER col2 TYPE text;
 Bad Request: Cannot change col2 from type bigint to type text: types are incompatible.

 ALTER TABLE mytable ALTER col3 TYPE bigint;
 Bad Request: Cannot change col3 from type text to type bigint: types are incompatible.

 ALTER TABLE mytable ALTER col3 TYPE int;
 Bad Request: Cannot change col3 from type text to type int: types are incompatible.

我错过了什么或做错了什么?非常感谢您的帮助。

从您链接的页面:

存储在该列的值中的字节保持不变,如果 现有数据无法根据新类型(您的CQL)进行[反序列化] 驱动程序或接口可能报告错误

因此,只能在兼容类型之间进行更改


这主要适用于从旧模式升级的用户,在旧模式中,所有列都定义为blob是很常见的。

谢谢。那么,什么是兼容类型?我很困惑,因为我认为将int/bigint更改为text应该可以正常工作,因为序列化不应该是一个问题。int总是4字节。文本是UTF-8,因此每个字符大约有一个字节,例如字符串“0”是一个字节,字符串“100000”是6。我在尝试将类型从float更改为decimal时遇到相同的错误,是否有解决方案?