Skip to content

Commit 48d8ad9

Browse files
committed
DynamoDb enhanced client: support UpdateExpressions in single-request update
1 parent 1e8e050 commit 48d8ad9

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/UpdateItemOperation.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,9 @@ public TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema, O
270270
}
271271

272272
/**
273-
* Generates the final UpdateExpression by merging expressions from multiple sources:
274-
* <ol>
275-
* <li><b>POJO attributes</b>: Creates SET/REMOVE actions for non-key attributes from the item POJO</li>
276-
* <li><b>Extension expressions</b>: Includes UpdateExpression from extensions (if any)</li>
277-
* <li><b>Request expressions</b>: Includes explicit UpdateExpression from the request (if any)</li>
278-
* </ol>
279-
*
280-
* <p><b>Conflict Detection:</b> All conflicts are detected server-side by DynamoDB and throw {@code DynamoDbException}.
281-
*
282-
* <p><b>Attribute Filtering:</b>
283-
* When {@code ignoreNulls} is false, null POJO attributes normally generate REMOVE actions.
284-
* However, attributes referenced in extension expressions are automatically excluded from
285-
* REMOVE actions to prevent DynamoDB conflicts between extension and POJO operations.
286-
*
273+
* Merges UpdateExpressions from POJO attributes, extensions, and request with priority-based resolution.
274+
* Attributes referenced in extension expressions are excluded from REMOVE actions to prevent conflicts.
275+
*
287276
* @param tableMetadata metadata about the table structure
288277
* @param transformation write modification from extensions containing UpdateExpression
289278
* @param attributes non-key attributes from the POJO item

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/update/UpdateExpressionResolver.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,14 @@ public static Builder builder() {
5353
}
5454

5555
/**
56-
* Merges UpdateExpressions from three sources in priority order:
57-
* <ol>
58-
* <li><b>Item attributes</b>: SET/REMOVE actions from item POJO (lowest priority)</li>
59-
* <li><b>Extension expressions</b>: Override conflicting item actions (medium priority)</li>
60-
* <li><b>Request expressions</b>: Override all other sources (highest priority)</li>
61-
* </ol>
62-
*
63-
* <p><b>Implementation steps:</b>
64-
* <ol>
65-
* <li>Find attributes referenced in extension and request expressions to exclude them from removal</li>
66-
* <li>Generate SET actions for all non-null item attributes</li>
67-
* <li>Generate REMOVE actions for null item attributes, excluding those referenced in expressions</li>
68-
* <li>Combine item SET and REMOVE expressions into a single item expression</li>
69-
* <li>Merge extension expressions with item expression (extension overrides conflicting item actions)</li>
70-
* <li>Merge request expressions with combined result (request overrides all conflicting actions)</li>
71-
* </ol>
72-
*
73-
* <p>Higher priority expressions win conflicts. REMOVE actions are filtered to prevent conflicts,
74-
* even when {@code ignoreNulls} is false.
75-
*
76-
* <p><b>Backward compatibility:</b> This enhancement is not a breaking change. Without request
77-
* expressions, behavior is identical to previous versions.
78-
*
79-
* <p><b>Exception scenarios:</b> DynamoDbException may be thrown when the same attribute is updated by multiple sources.
56+
* Merges UpdateExpressions from three sources with priority: item attributes (lowest),
57+
* extension expressions (medium), request expressions (highest).
58+
*
59+
* <p><b>Steps:</b> Find attributes in expressions to exclude from removal → generate item SET/REMOVE actions
60+
* → merge with extension expressions → merge with request expressions.
61+
*
62+
* <p><b>Backward compatibility:</b> Without request expressions, behavior is identical to previous versions.
63+
* <p><b>Exceptions:</b> DynamoDbException may be thrown when the same attribute is updated by multiple sources.
8064
*
8165
* @return merged UpdateExpression, or empty if no updates needed
8266
*/

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/TransactUpdateItemEnhancedRequest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,9 @@ public Builder<T> item(T item) {
249249
/**
250250
* Specifies custom update operations using DynamoDB's native update expression syntax. Enables advanced modifications
251251
* like incrementing counters or modifying lists/sets.
252-
* <p>
253-
* <b>Precedence:</b> Request expressions (highest) > Extension expressions > Item attributes (lowest).
252+
* <p><b>Precedence:</b> Request expressions (highest) > Extension expressions > Item attributes (lowest).
254253
* This method overrides any conflicting operations from item attributes or extensions.
255-
* <p>
256-
* <b>Backward compatible:</b> New feature that doesn't affect existing behavior when not used.
254+
* <p><b>Backward compatible:</b> New feature that doesn't affect existing behavior when not used.
257255
*
258256
* @param updateExpression the update operations to perform
259257
* @return a builder of this type

0 commit comments

Comments
 (0)