From b723a9c519b15372a4dc8f01a434b43e504bbc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Tafral=C4=B1?= Date: Wed, 8 Apr 2026 08:36:06 +0300 Subject: [PATCH] fix: add list_append support to DynamoDB update expressions (#277) DynamoDbService was not handling the list_append function in update expressions. This adds the logic to extract both list arguments, resolve them from expression attributes or item attributes, and merge them into the DynamoDB list format (with "L" structure). Includes integration test covering basic list append operation. --- .../services/dynamodb/DynamoDbService.java | 22 +++++ .../dynamodb/DynamoDbIntegrationTest.java | 83 +++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java index f9fbc8000c..134f29f524 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java @@ -961,6 +961,28 @@ public class DynamoDbService { item.set(attrName, resolved); } } + } else if (valuePart.startsWith("list_append(")) { + String[] args = extractFunctionArgs(valuePart); + if (args.length == 2) { + String arg1 = args[0].trim(); + String arg2 = args[1].trim(); + JsonNode list1 = arg1.startsWith(":") && exprAttrValues != null + ? exprAttrValues.get(arg1) + : item.get(resolveAttributeName(arg1, exprAttrNames)); + JsonNode list2 = arg2.startsWith(":") && exprAttrValues != null + ? exprAttrValues.get(arg2) + : item.get(resolveAttributeName(arg2, exprAttrNames)); + if (list1 != null && list2 != null && list1.has("L") && list2.has("L")) { + com.fasterxml.jackson.databind.node.ArrayNode merged = + com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.arrayNode(); + list1.get("L").forEach(merged::add); + list2.get("L").forEach(merged::add); + com.fasterxml.jackson.databind.node.ObjectNode result = + com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + result.set("L", merged); + item.set(attrName, result); + } + } } else if (valuePart.startsWith(":") && exprAttrValues != null) { JsonNode value = exprAttrValues.get(valuePart); if (value != null) { diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java index 2789ab4bb0..cf783caa8e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java @@ -748,6 +748,89 @@ class DynamoDbIntegrationTest { .body("__type", equalTo("ResourceNotFoundException")); } + @Test + @Order(27) + void updateItemListAppend() { + // Create a table for this test + given() + .header("X-Amz-Target", "DynamoDB_20120810.CreateTable") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "ListAppendTable", + "KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}], + "AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}], + "BillingMode": "PAY_PER_REQUEST" + } + """) + .when() + .post("/") + .then() + .statusCode(200); + + // Put item with initial list + given() + .header("X-Amz-Target", "DynamoDB_20120810.PutItem") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "ListAppendTable", + "Item": {"pk": {"S": "k1"}, "items": {"L": [{"S": "a"}]}} + } + """) + .when() + .post("/") + .then() + .statusCode(200); + + // Append to list + given() + .header("X-Amz-Target", "DynamoDB_20120810.UpdateItem") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "ListAppendTable", + "Key": {"pk": {"S": "k1"}}, + "UpdateExpression": "SET items = list_append(items, :val)", + "ExpressionAttributeValues": {":val": {"L": [{"S": "b"}]}} + } + """) + .when() + .post("/") + .then() + .statusCode(200); + + // Verify both elements present + given() + .header("X-Amz-Target", "DynamoDB_20120810.GetItem") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "ListAppendTable", + "Key": {"pk": {"S": "k1"}} + } + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("Item.items.L.size()", equalTo(2)) + .body("Item.items.L[0].S", equalTo("a")) + .body("Item.items.L[1].S", equalTo("b")); + + // Cleanup + given() + .header("X-Amz-Target", "DynamoDB_20120810.DeleteTable") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + {"TableName": "ListAppendTable"} + """) + .when() + .post("/") + .then() + .statusCode(200); + } + @Test void unsupportedOperation() { given()