Cassandra CQL 3.2.1 清除列数据

Cassandra CQL 3.2.1 Clear column data

我需要使用 CQL 从 table 中的列中清除数据 我在单个节点上尝试了以下测试,它工作正常。

但这会在许多节点和不同的复制因子上运行吗?

DROP KEYSPACE IF EXISTS testColumnDrop;

CREATE KEYSPACE testColumnDrop WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

USE testColumnDrop;

CREATE TABLE contracts (
  id varchar PRIMARY KEY,
  licenses varchar
);

INSERT INTO contracts(id, licenses) VALUES('one', '{"number":"1.0"}');
INSERT INTO contracts(id, licenses) VALUES('two', '{"number":"2.0"}');
INSERT INTO contracts(id, licenses) VALUES('three', '{"number":"3.0"}');

SELECT * FROM contracts;

ALTER TABLE contracts DROP licenses;

ALTER TABLE contracts ADD licenses varchar;

SELECT * FROM contracts;

来自 DataStax 文档:

ALTER DROP removes the column from the table definition, removes data pertaining to that column, and eventually reclaims the space formerly used by the column. The column is unavailable for querying immediately after being dropped. The actual data removal occurs during compaction; data is not included in SSTables in the future. To force the removal of dropped columns before compaction occurs, use the nodetool upgradesstables command followed by an ALTER TABLE statement, which updates the table metadata to register the drop.

After re-adding a dropped column, a query does not return values written before the column was last dropped. Do not re-add a dropped column to a table using client-supplied timestamps, which is not a Cassandra-generated write time.

You cannot drop columns from tables defined with the COMPACT STORAGE option.

希望对您有所帮助

我尝试使用 Docker 和一个由三个节点组成的集群,效果很好