mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(dynamodb): apply the ProjectionExpression of a TransactGetItems Get (#4061)
The projection was validated and then ignored, so every Get returned the whole item. A projection selecting no attribute leaves the entry without an Item, where GetItem and BatchGetItem both keep an empty one.
This commit is contained in:
1 parent
c62db2de1e
commit
138f3c2650
2 files changed
+76
-1
No files matched your search
@@ -1825,7 +1825,7 @@ public class DynamoDbService implements ResourceProvider {
|
||||
String tableName = get.path("TableName").asText();
|
||||
JsonNode key = get.get("Key");
|
||||
try {
|
||||
results.add(getItem(tableName, key, region));
|
||||
results.add(projectTransactGet(getItem(tableName, key, region), get));
|
||||
cancelReasons.add(new TransactionCanceledException.CancellationReason("", null));
|
||||
} catch (AwsException e) {
|
||||
if ("ValidationException".equals(e.getErrorCode())) {
|
||||
@@ -1849,6 +1849,20 @@ public class DynamoDbService implements ResourceProvider {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetItem and BatchGetItem keep an empty Item when the projection matches nothing.
|
||||
* TransactGetItems omits it.
|
||||
*/
|
||||
private JsonNode projectTransactGet(JsonNode item, JsonNode get) {
|
||||
String projectionExpression = get.path("ProjectionExpression").textValue();
|
||||
if (item == null || projectionExpression == null) {
|
||||
return item;
|
||||
}
|
||||
ObjectNode projected = ProjectionEvaluator.project(item, projectionExpression,
|
||||
get.has("ExpressionAttributeNames") ? get.get("ExpressionAttributeNames") : null);
|
||||
return projected.isEmpty() ? null : projected;
|
||||
}
|
||||
|
||||
// --- UpdateTable ---
|
||||
|
||||
public TableDefinition updateTable(String tableName, Long readCapacity, Long writeCapacity, String region) {
|
||||
|
||||
Reference in new issue
Block a user