-
Notifications
You must be signed in to change notification settings - Fork 912
Support AutoGeneratedTimestamp and UpdateBehavior annotation in nested objects #6109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
eed3945
to
e2225c5
Compare
Please run the checkstyle plugin on When I do it by runing the following command
|
The test coverage checklist is not complete, could you comment on the test that aren't run to validate they are not required for this change? |
Could you explain why are we also making this change? Could this impact existing customers using |
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
…oDbUpdateBehavior on attributes within nested objects
3d9ab1a
to
71c57d5
Compare
Based on my understanding while debugging the code, there are two distinct ways of handling nested objects during the update flow, which depend on the IgnoreNullsMode parameter. This influences whether or not the transformItemToMapForUpdateExpression() method is invoked to flatten the request. For IgnoreNullsMode.MAPS_ONLY, the entire nested object is expected to be set as a map. In this case, UpdateExpressionUtils cannot apply if_not_exists() to individual fields annotated with @DynamoDbUpdateBehavior, since the update is applied at the object level. However, in IgnoreNullsMode.SCALAR_ONLY, where nested fields are flattened using NESTED_ATTR_UPDATE as a delimiter, if_not_exists() can be applied to each individual attribute in the final update expression. That’s how I interpret the current behavior from the code. The existing logic for parent-level attributes remains unaffected by this behavior—regardless of the IgnoreNullsMode used. This is a limitation that applies only to annotated nested fields, which were not previously supported by this extension. As such, I don’t see any breaking changes for existing use cases involving parent-level attributes. |
|
@@ -64,13 +72,17 @@ | |||
* <p> | |||
* Every time a new update of the record is successfully written to the database, the timestamp at which it was modified will | |||
* be automatically updated. This extension applies the conversions as defined in the attribute convertor. | |||
* The implementation handles both flattened nested parameters (identified by keys separated with | |||
* {@code "_NESTED_ATTR_UPDATE_"}) and entire nested maps or lists, ensuring consistent behavior across both representations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we clarify here the difference in null value handling?
if (value.hasM() && value.m() != null) { | ||
Optional<? extends TableSchema<?>> nestedSchema = getNestedSchema(context.tableSchema(), key); | ||
if (nestedSchema.isPresent()) { | ||
Map<String, AttributeValue> processed = processNestedObject(value.m(), nestedSchema.get(), currentInstant); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possible performance degradation for deeply nested records?
return WriteModification.builder() | ||
.transformedItem(Collections.unmodifiableMap(itemToTransform)) | ||
.build(); | ||
} | ||
|
||
private TableSchema<?> getTableSchemaForListElement(TableSchema<?> rootSchema, String key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these private utility functions seem generic to nested records rather than to auto generated timestamps - I'm not against keeping them here since it limits the scope and I'm not all that familiar with this library - but would it make sense to move these to a utility?
Description
Added support for @DynamoDbAutoGeneratedTimestampAttribute and @DynamoDbUpdateBehavior on attributes within nested objects. The @DynamoDbUpdateBehavior annotation will only take effect for nested attributes when using IgnoreNullsMode.SCALAR_ONLY.
Motivation and Context
@DynamoDbUpdateBehavior and @DynamoDbAutoGeneratedTimestampAttribute to work on nested objects too.
Modifications
The AutoGeneratedTimestampRecordExtension has been enhanced to support detection of the timestamp annotation on nested objects. Depending on the operation and the IgnoreNullsMode setting, nested attributes may either be treated as complete maps or flattened using the NESTED_ATTR_UPDATE convention (handled in transformItemToMapForUpdateExpression within UpdateItemOperation). Both scenarios are now supported, and the same generated timestamp is applied consistently across top-level and nested fields.
In parallel, the handling of the IgnoreNullsMode parameter within update requests was reviewed. As a result, UpdateExpressionUtils has been updated to evaluate the @DynamoDbUpdateBehavior annotation only when IgnoreNullsMode.SCALAR_ONLY is used, targeting flattened nested attributes identified via NESTED_ATTR_UPDATE.
When applied to a list of nested objects, the annotation is not supported, as individual elements cannot be updated — the entire list is replaced during an update operation.
Testing
Existing tests were updated, and new tests were added to validate the extended functionality.
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License
Test Coverage Checklist