Support multiple Update operations for the same column
Update stores one column name as key and one operation as value.
https://github.com/spring-projects/spring-data-cassandra/blob/67d8e597ae900b1c2f1eb145e76755cb25a1bb57/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/query/Update.java#L49
Because of this it is not possible to update several keys for column with map type.
Example of code:
CREATE TABLE data (fields map<VARCHAR, VARCHAR>);
List<Update.AssignmentOp> updateOperations = new LinkedList<>();
updateOperations.add(new Update.SetAtKeyOp(ColumnName.from("map"), "key1", "value1"));
updateOperations.add(new Update.SetAtKeyOp(ColumnName.from("map"), "key2", "value2"));
Update update = Update.of(updateOperations);
OR
Update update = Update.empty()
.set("map").atKey("key1").to("value1")
.set("map").atKey("key2").to("value2");
only one of operations will be present in update object.
As a workaround possible to create custom ColumnName which will return different equals/hashCode to identical column names.
This is indeed a limitation of the current implementation. Our API should be able to support multiple operations per column and that will be a neat enhancement.
Hi @mp911de Could you confirm if this still needs to be fixed?
Confirmed. Update should contain a List of operations and and we need to define what happens if you try to update the same element (same column or same key in a map) twice. Replacing (as of today) seems a good idea, we also should document what we're doing.
could you pls assign this ticket to me, so that i can start with it?
Hi! I noticed this issue was assigned a while ago, but it doesn’t seem to have any recent updates. If it’s alright, I’d be happy to take over and work on it. Let me know what you think. Thanks!
Sure, feel free to submit a pull request.
Hello, this PR for https://github.com/spring-projects/spring-data-cassandra/pull/1596 is ready for review, PTAL when you get a chance, thanks!