zoukankan      html  css  js  c++  java
  • Cassandra 类型转换限制

    原文地址:http://stackoverflow.com/questions/31880381/cassandra-alter-column-type-which-types-are-compatible
    版本: Cassandra 2.2.0
    2016年6月1日更新,版本3.0+

    Cassandra并不像mysql一样几乎支持几乎所有的类型间转换,下面是一个支持转换的列表

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

    注意:
    几乎所有类型都可以转换到blob
    cqlsh 允许 varint 转换为 date,但是这是bug,不要尝试

    alter table user alter user_name type blob;
    

    如果你想曲线救国

    我先drop 再 add 这个字段,不行

    你会看到提示

    InvalidRequest: code=2200 [Invalid query] message="Cannot add a collection with the name pics because a collection with the same name and a different type has already been used in the past"

    这是一个bug
    https://issues.apache.org/jira/browse/CASSANDRA-9816

    最新版本可以试试是否已经修复

    2016年6月1日更新

    3.0 alpha 1 说已经修复,下面是测试结果:

    kevin@cqlsh:test> alter table user drop user_name;
    kevin@cqlsh:test> alter table user add user_name int;
    kevin@cqlsh:test> select * from user;
    
     uid | user_name
    -----+-----------
    
    (0 rows)
    kevin@cqlsh:test> insert into user(uid,user_name) values(1,'kevin');
    InvalidRequest: code=2200 [Invalid query] message="Invalid STRING constant (kevin) for "user_name" of type int"
    kevin@cqlsh:test> insert into user(uid,user_name) values(1,233);
    kevin@cqlsh:test> select * from user;
    
     uid | user_name
    -----+-----------
       1 |       233
    
    (1 rows)
    kevin@cqlsh:test> alter table user drop user_name;
    kevin@cqlsh:test> alter table user add user_name text;
    kevin@cqlsh:test> insert into user(uid,user_name) values(1,'kevin');
    kevin@cqlsh:test> select * from user;
    
     uid | user_name
    -----+-----------
       1 |     kevin
    
    (1 rows)
    

    现在,你可以曲线救国了。。。

  • 相关阅读:
    51nod 1179 最大的最大公约数 (数论)
    POJ 3685 二分套二分
    POJ 3045 贪心
    LIC
    HDU 1029 Ignatius and the Princess IV
    HDU 1024 Max Sum Plus Plus
    HDU 2389 Rain on your Parade
    HDU 2819 Swap
    HDU 1281 棋盘游戏
    HDU 1083 Courses
  • 原文地址:https://www.cnblogs.com/didda/p/5072393.html
Copyright © 2011-2022 走看看