-
Notifications
You must be signed in to change notification settings - Fork 979
Support AutoGeneratedTimestamp annotations in nested objects #6546
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
Open
anasatirbasa
wants to merge
29
commits into
aws:master
Choose a base branch
from
anasatirbasa:feature/support-autoGeneratedTimestamp-and-updateBehavior-annotations-in-nested-objects
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
778d12b
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa d60f5dd
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa 56d0d49
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa 471dc58
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa 0f3b61a
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa af027ad
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa 480827d
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa 3412f52
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa cabe751
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa 63b6c82
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa 772e2f3
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa 55bcc06
Support AutoGeneratedTimestamp and UpdateBehavior annotations in nest…
anasatirbasa cf6c8f2
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa e829dcb
Exclude nested update behavior functionality
anasatirbasa ab4c683
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa e1636a7
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa 1947ac6
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa c9c0787
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa 7bdc3aa
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa 7cef75e
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa d8bc88b
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa ba342bf
Added support for @DynamoDbAutoGeneratedTimestampAttribute on attribu…
anasatirbasa 9b1ae1f
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
shetsa-amzn ca1b464
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa 3141ee4
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa 6348ef0
Fixed caching mechanism for nested schemas.
anasatirbasa f9eea6c
Merge remote-tracking branch 'origin/feature/support-autoGeneratedTim…
anasatirbasa 13c861a
Merge branch 'master' into feature/support-autoGeneratedTimestamp-and…
anasatirbasa 7fc4441
fixed checkstyle
anasatirbasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changes/next-release/feature-AmazonDynamoDBEnhancedClient-96aff9e.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "type": "feature", | ||
| "category": "Amazon DynamoDB Enhanced Client", | ||
| "contributor": "", | ||
| "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." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...ftware/amazon/awssdk/enhanced/dynamodb/internal/extensions/utility/NestedRecordUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.enhanced.dynamodb.internal.extensions.utility; | ||
|
|
||
| import static software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.getNestedSchema; | ||
| import static software.amazon.awssdk.enhanced.dynamodb.internal.operations.UpdateItemOperation.NESTED_OBJECT_UPDATE; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.regex.Pattern; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.enhanced.dynamodb.TableSchema; | ||
| import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | ||
|
|
||
| @SdkInternalApi | ||
| public final class NestedRecordUtils { | ||
|
|
||
| private static final Pattern NESTED_OBJECT_PATTERN = Pattern.compile(NESTED_OBJECT_UPDATE); | ||
|
|
||
| private NestedRecordUtils() { | ||
| } | ||
|
|
||
| /** | ||
| * Resolves and returns the {@link TableSchema} for the element type of a list attribute from the provided root schema. | ||
| * <p> | ||
| * This method is useful when dealing with lists of nested objects in a DynamoDB-enhanced table schema, particularly in | ||
| * scenarios where the list is part of a flattened nested structure. | ||
| * <p> | ||
| * If the provided key contains the nested object delimiter (e.g., {@code _NESTED_ATTR_UPDATE_}), the method traverses the | ||
| * nested hierarchy based on that path to locate the correct schema for the target attribute. Otherwise, it directly resolves | ||
| * the list element type from the root schema using reflection. | ||
| * | ||
| * @param rootSchema The root {@link TableSchema} representing the top-level entity. | ||
| * @param key The key representing the list attribute, either flat or nested (using a delimiter). | ||
| * @return The {@link TableSchema} representing the list element type of the specified attribute. | ||
| * @throws IllegalArgumentException If the list element class cannot be found via reflection. | ||
| */ | ||
| public static TableSchema<?> getTableSchemaForListElement(TableSchema<?> rootSchema, String key) { | ||
| TableSchema<?> listElementSchema; | ||
| try { | ||
| if (!key.contains(NESTED_OBJECT_UPDATE)) { | ||
| Optional<? extends TableSchema<?>> staticSchema = getNestedSchema(rootSchema, key); | ||
| listElementSchema = | ||
| staticSchema.isPresent() | ||
| ? staticSchema.get() | ||
| : TableSchema.fromClass(Class.forName( | ||
| rootSchema.converterForAttribute(key).type().rawClassParameters().get(0).rawClass().getName())); | ||
|
|
||
| } else { | ||
| String[] parts = NESTED_OBJECT_PATTERN.split(key); | ||
| TableSchema<?> currentSchema = rootSchema; | ||
|
|
||
| for (int i = 0; i < parts.length - 1; i++) { | ||
| Optional<? extends TableSchema<?>> nestedSchema = getNestedSchema(currentSchema, parts[i]); | ||
| if (nestedSchema.isPresent()) { | ||
| currentSchema = nestedSchema.get(); | ||
| } | ||
| } | ||
| String attributeName = parts[parts.length - 1]; | ||
| Optional<? extends TableSchema<?>> nestedListSchema = getNestedSchema(currentSchema, attributeName); | ||
| listElementSchema = nestedListSchema | ||
| .orElseThrow(() -> new IllegalArgumentException("Unable to resolve schema for list element at: " + key)); | ||
| } | ||
| } catch (ClassNotFoundException e) { | ||
| throw new IllegalArgumentException("Class not found for field name: " + key, e); | ||
| } | ||
| return listElementSchema; | ||
| } | ||
|
|
||
| /** | ||
| * Traverses the attribute keys representing flattened nested structures and resolves the corresponding {@link TableSchema} | ||
| * for each nested path. | ||
| * <p> | ||
| * The method constructs a mapping between each unique nested path (represented as dot-delimited strings) and the | ||
| * corresponding {@link TableSchema} object derived from the root schema. It supports resolving schemas for arbitrarily deep | ||
| * nesting, using the {@code _NESTED_ATTR_UPDATE_} pattern as a path delimiter. | ||
| * <p> | ||
| * This is typically used in update or transformation flows where fields from nested objects are represented as flattened keys | ||
| * in the attribute map (e.g., {@code parent_NESTED_ATTR_UPDATE_child}). | ||
| * | ||
| * @param attributesToSet A map of flattened attribute keys to values, where keys may represent paths to nested attributes. | ||
| * @param rootSchema The root {@link TableSchema} of the top-level entity. | ||
| * @return A map where the key is the nested path (e.g., {@code "parent.child"}) and the value is the {@link TableSchema} | ||
| * corresponding to that level in the object hierarchy. | ||
| */ | ||
| public static Map<String, TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeValue> attributesToSet, | ||
| TableSchema<?> rootSchema) { | ||
| Map<String, TableSchema<?>> schemaMap = new HashMap<>(); | ||
| schemaMap.put("", rootSchema); | ||
|
|
||
| for (String key : attributesToSet.keySet()) { | ||
| String[] parts = NESTED_OBJECT_PATTERN.split(key); | ||
|
|
||
| StringBuilder pathBuilder = new StringBuilder(); | ||
| TableSchema<?> currentSchema = rootSchema; | ||
|
|
||
| for (int i = 0; i < parts.length - 1; i++) { | ||
| if (pathBuilder.length() > 0) { | ||
| pathBuilder.append("."); | ||
| } | ||
| pathBuilder.append(parts[i]); | ||
|
|
||
| String path = pathBuilder.toString(); | ||
|
|
||
| if (!schemaMap.containsKey(path)) { | ||
| Optional<? extends TableSchema<?>> nestedSchema = getNestedSchema(currentSchema, parts[i]); | ||
| if (nestedSchema.isPresent()) { | ||
| schemaMap.put(path, nestedSchema.get()); | ||
| currentSchema = nestedSchema.get(); | ||
| } | ||
| } else { | ||
| currentSchema = schemaMap.get(path); | ||
| } | ||
| } | ||
| } | ||
| return schemaMap; | ||
| } | ||
|
|
||
| public static String reconstructCompositeKey(String path, String attributeName) { | ||
| if (path == null || path.isEmpty()) { | ||
| return attributeName; | ||
| } | ||
| return String.join(NESTED_OBJECT_UPDATE, path.split("\\.")) | ||
| + NESTED_OBJECT_UPDATE + attributeName; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.