feat: support DynamoDB UPDATED_OLD and UPDATED_NEW ReturnValues (#477)

This commit is contained in:
bkindersleytrulioo authored and GitHub committed 2026-04-16 17:20:24 -05:00
1 parent 5f07c77237
commit 3ebff5a701
2 files changed
+286

No files matched your search

@@ -291,11 +291,36 @@ public class DynamoDbJsonHandler {
response.set("Attributes", result.newItem());
} else if ("ALL_OLD" .equals(returnValues) && result.oldItem() != null) {
response.set("Attributes", result.oldItem());
} else if ("UPDATED_NEW".equals(returnValues) && result.oldItem() != null && result.newItem() != null) {
response.set("Attributes", getChangedAttributes(result.newItem(), result.oldItem()));
} else if ("UPDATED_OLD".equals(returnValues) && result.oldItem() != null && result.newItem() != null) {
response.set("Attributes", getChangedAttributes(result.oldItem(), result.newItem()));
}
addConsumedCapacity(response, request, tableName, 1, true);
return Response.ok(response).build();
}
private JsonNode getChangedAttributes(JsonNode preferredItem, JsonNode secondaryItem){
ObjectNode changedAttributes = objectMapper.createObjectNode();
Iterator<Map.Entry<String, JsonNode>> fields = preferredItem.fields();
while (fields.hasNext()) {
var entry = fields.next();
String attrName = entry.getKey();
JsonNode value = entry.getValue();
if (secondaryItem.has(attrName)){
JsonNode secondaryValue = secondaryItem.get(attrName);
if (!value.equals(secondaryValue)){
changedAttributes.put(attrName, value);
}
}
else {
changedAttributes.put(attrName, value);
}
}
return changedAttributes;
}
private Response handleQuery(JsonNode request, String region) {
String tableName = request.path("TableName").asText();
JsonNode keyConditions = request.has("KeyConditions") ? request.get("KeyConditions") : null;