我有一个cassandra表,想删除一行,但前提是只有一列具有一个特定值。
即使cassandra声称删除成功(它返回“ applied:true”),消息仍然存在。
让我们创建表并插入一些数据:
CREATE TABLE IF NOT EXISTS test
(
id uuid PRIMARY KEY,
recipient text,
message text
);
INSERT INTO test (id, recipient, message)
VALUES (7ee055ee-b5dd-4bfd-b184-614d51e268d5, 'felix', 'foo');
INSERT INTO test (id, recipient, message)
VALUES (86c9d632-dc24-4635-8277-c987c78bd242, 'andrew', 'bar');
现在,我想删除一封邮件,但前提是请求删除的用户(在本例中为felix)是收件人,因此有权这样做:
cqlsh:service_message> DELETE FROM test WHERE id=7ee055ee-b5dd-4bfd-b184-614d51e268d5 IF recipient='felix';
[applied]
-----------
True
所以我现在认为查询确实成功了,但是如果我们看一下表,就会发现消息仍然存在。
cqlsh:service_message> SELECT * FROM test;
id | message | recipient
--------------------------------------+---------+-----------
86c9d632-dc24-4635-8277-c987c78bd242 | bar | andrew
7ee055ee-b5dd-4bfd-b184-614d51e268d5 | foo | felix
(2 rows)
一些其他信息:
cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4
cqlsh> DESCRIBE KEYSPACE service_message
CREATE KEYSPACE service_message WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;
CREATE TABLE service_message.test (
id uuid PRIMARY KEY,
message text,
recipient text
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';
答案 0 :(得分:0)
INSERT and UPDATE statements using the IF clause support lightweight transactions
。
来自CQL上的Datastax文档:https://docs.datastax.com/en/cql/3.3/cql/cql_using/useInsertLWT.html
我很确定不支持删除。如果要有效删除信息,可以考虑将UPDATE语句中单元格的值设置为null。通过删除或设置为空,您仍在创建逻辑删除。