fix(dynamodb): support REMOVE for nested map paths (#402) (#421)

applyRemoveClause() only handled top-level attributes, treating
"ratings.foo" as a literal key name instead of navigating into the
map structure. Add removeValueAtPath() that splits the path into
segments, resolves expression attribute names, and navigates through
nested Map wrappers (M field) to remove the target key.

Includes unit tests for nested paths, expression attribute names,
non-existent paths, and 3-level deep nesting, plus an AWS CLI
compat test reproducing the original report.
This commit is contained in:
TiM authored and GitHub committed 2026-04-13 20:07:58 -05:00
1 parent d16945f30d
commit 0ef82f0079
3 files changed
+211 -2

No files matched your search

@@ -1058,8 +1058,7 @@ public class DynamoDbService {
}
}
String attrName = resolveAttributeName(attrPart, exprAttrNames);
item.remove(attrName);
removeValueAtPath(item, attrPart, exprAttrNames);
}
return clause;
}
@@ -1365,6 +1364,45 @@ public class DynamoDbService {
return getValueAtPath(item, path, exprAttrNames) != null;
}
/**
* Removes a value at a potentially nested attribute path.
* Supports paths like "attr", "parent.child", "#alias.nested" etc.
* For nested paths, navigates into the DynamoDB Map structure (M field)
* and removes the final key from its parent.
*/
private void removeValueAtPath(ObjectNode item, String path, JsonNode exprAttrNames) {
String[] segments = path.split("\\.");
for (int i = 0; i < segments.length; i++) {
segments[i] = resolveAttributeName(segments[i].trim(), exprAttrNames);
}
if (segments.length == 1) {
item.remove(segments[0]);
return;
}
// Navigate to the parent of the target attribute
ObjectNode current = item;
for (int i = 0; i < segments.length - 1; i++) {
String segment = segments[i];
JsonNode child = current.get(segment);
if (child == null || !child.has("M")) {
// Path doesn't exist, nothing to remove
return;
}
JsonNode mapContent = child.get("M");
if (mapContent instanceof ObjectNode) {
current = (ObjectNode) mapContent;
} else {
return;
}
}
current.remove(segments[segments.length - 1]);
}
private int findNextComma(String s) {
// Find next comma that is not inside a function call
int depth = 0;