【发布时间】:2020-11-27 10:00:49
【问题描述】:
我有一个要求,我必须在使用 spring 和 springboot 的批处理操作下仅使用分区键(使用分区键删除所有记录)在 cassandra 中执行删除操作,但 CassandraBatchOperations 的删除方法只接受输入完整的实体对象,如
CassandraBatchOperations delete(Object... entities);
我有一张桌子说 table1 它有钥匙: key1- 分区键, key2 - 聚类 key1 , key 3-clustering key2
so my requirement is that in batch operation below query should run
DELETE from table1 where key1='input key';
so when i create an object like
tableEntity recordToDelete=new Table1Entity();
recordToDelete.setKey1('input key');
and run batchOperations like
CassandraBatchOperations batchOps=cassandraTemplate.batchOps();
batchOps.delete(recordToDelete);
then the effective query getting generated is
DELETE from table1 where key1='input key' and key2=null and key3=null
然后我得到以下异常
> rg.springframework.data.cassandra.CassandraInvalidQueryException:
> Query; CQL [BEGIN BATCH DELETE FROM table1 WHERE key2=null AND
> key3=null AND key1='0002';APPLY BATCH;]; Invalid null value in
> condition for column key2; nested exception is
> com.datastax.driver.core.exceptions.InvalidQueryException: Invalid
> null value in condition for column key2
问题是获取创建的查询还考虑了集群键 key2 和 key3 没有值,因为我只想通过分区键删除。
我想知道如何仅通过分区键删除, 从数据库获取记录列表不是一个选项,因为我还在同一批处理操作下将记录插入到 cassandra 中,并且可能会发生在同一批处理操作中插入的记录,它具有我想要的分区键删除 。所以在这种情况下,如果我获取并删除记录,在批处理操作中插入的新记录将不会被删除。
【问题讨论】:
标签: java spring spring-boot cassandra