spring-data-cassandra icon indicating copy to clipboard operation
spring-data-cassandra copied to clipboard

Support multiple Update operations for the same column

Open ivan-zaitsev opened this issue 1 year ago • 5 comments

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.

ivan-zaitsev avatar Oct 14 '24 15:10 ivan-zaitsev

As a workaround possible to create custom ColumnName which will return different equals/hashCode to identical column names.

ivan-zaitsev avatar Oct 14 '24 18:10 ivan-zaitsev

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.

mp911de avatar Oct 15 '24 06:10 mp911de

Hi @mp911de Could you confirm if this still needs to be fixed?

nemogpt avatar Mar 14 '25 21:03 nemogpt

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.

mp911de avatar Mar 19 '25 14:03 mp911de

could you pls assign this ticket to me, so that i can start with it?

nemogpt avatar Mar 19 '25 15:03 nemogpt

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!

m3k0813 avatar Aug 06 '25 15:08 m3k0813

Sure, feel free to submit a pull request.

mp911de avatar Aug 07 '25 06:08 mp911de

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!

m3k0813 avatar Aug 11 '25 08:08 m3k0813