4

Cassandra でテーブルの列の型を変更するのに問題があります。

これは、列が PRIMARY KEY の一部ではなく、INDEX がない場合に型を変更できるというドキュメントへのリンクです。私はそれを機能させることができません。

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.

私は何が欠けているか、間違っていますか? どんな助けでも大歓迎です。

4

1 に答える 1

3

リンクしたページから:

その列の値に格納されているバイトは変更されず、新しい型に従って既存のデータを [逆シリアル化] できない場合、CQL ドライバーまたはインターフェイスがエラーを報告する可能性があります。

したがって、互換性のあるタイプ間でのみ変更できます。

これは主に、すべての列を blob として定義したままにしておくことが一般的だった Thrift スキーマからアップグレードする人々を対象としています。

于 2014-01-19T14:25:03.570 に答える