-
Notifications
You must be signed in to change notification settings - Fork 885
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
DDB Enhanced:Added support to read Nested objects in attributesToProj… #2035
Conversation
.../dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/AttributeName.java
Outdated
Show resolved
Hide resolved
.../dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/AttributeName.java
Outdated
Show resolved
Hide resolved
/** | ||
* @return List of nested attributes , each entry in the list represent one level of nesting. | ||
*/ | ||
public List getNestedAttributeNames() { |
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.
Why are you returning a raw-type list here?
.../dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/AttributeName.java
Outdated
Show resolved
Hide resolved
private String attributeToProject; | ||
|
||
private Builder() { | ||
|
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.
Nit: remove this empty line.
private final String name; | ||
private final List<String> nestedAttributeNames; | ||
|
||
private AttributeName(String name, List<String> nestedAttributeNames) { |
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.
Minor: Our standard pattern is to have a constructor that takes an instance of a builder. Eg:
private AttributeName(Builder b) { ... }
.../dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/AttributeName.java
Outdated
Show resolved
Hide resolved
private final List<String> attributesToProject; | ||
private final List<AttributeName> attributeNamesToProject; |
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.
My opinion is that we should deprecate the List and just have a List. That will simplify our behavioral logic around this.
...anced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/QueryEnhancedRequest.java
Outdated
Show resolved
Hide resolved
.../java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/utils/OperationUtils.java
Outdated
Show resolved
Hide resolved
Looks like the previous PR was closed; for future PR's please use the existing pull request when making updates so we can maintain the history |
...odb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/NestedAttributeName.java
Show resolved
Hide resolved
...odb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/NestedAttributeName.java
Outdated
Show resolved
Hide resolved
...odb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/NestedAttributeName.java
Outdated
Show resolved
Hide resolved
...odb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/NestedAttributeName.java
Outdated
Show resolved
Hide resolved
...odb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/NestedAttributeName.java
Outdated
Show resolved
Hide resolved
@@ -347,7 +360,101 @@ public Builder addAttributeToProject(String attributeToProject) { | |||
return this; | |||
} | |||
|
|||
/** | |||
* <p> | |||
* Sets a collection of the NestedAttributeNames to be retrieved from the database. These attributes can include |
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.
Change 'sets' to 'adds'
...anced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/QueryEnhancedRequest.java
Outdated
Show resolved
Hide resolved
...anced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/QueryEnhancedRequest.java
Outdated
Show resolved
Hide resolved
...anced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/QueryEnhancedRequest.java
Outdated
Show resolved
Hide resolved
...hanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/ScanEnhancedRequest.java
Outdated
Show resolved
Hide resolved
@@ -192,7 +206,8 @@ public int hashCode() { | |||
private Integer limit; | |||
private Boolean consistentRead; | |||
private Expression filterExpression; | |||
private List<String> attributesToProject; | |||
private List<String> attributesToProjectStringList; |
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.
attributesToProjectStringList attribute is required to maintain the order of the older attributeToProject in cases of resets.
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 the order important? Conceptually I think of this as a 'set'.
...odb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/NestedAttributeName.java
Outdated
Show resolved
Hide resolved
this.elements = nestedAttributeNames != null | ||
? Collections.unmodifiableList(nestedAttributeNames) : null; |
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.
Having null elements should be invalid. Can we add a validator here?
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.
Added for Null as well as Empty list
return attributesToProject != null ? attributesToProject.stream().filter(Objects::nonNull) | ||
.map(item -> String.join(".", item.elements())).collect(Collectors.toList()) : null; |
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.
I feel like we should add validation to the constructor of the class to avoid the possibility of having null elements in attributesToProject then there would be no need to filter them here.
@@ -192,7 +206,8 @@ public int hashCode() { | |||
private Integer limit; | |||
private Boolean consistentRead; | |||
private Expression filterExpression; | |||
private List<String> attributesToProject; | |||
private List<String> attributesToProjectStringList; |
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 the order important? Conceptually I think of this as a 'set'.
//If there is a reset then clear the attributesToProject List. | ||
if (attributesToProjectStringList != null) { | ||
attributesToProjectStringList | ||
.forEach(attribute -> this.attributesToProject.remove(NestedAttributeName.create(attribute))); | ||
} |
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.
I think this is really confusing. We don't want to treat these as separate lists. We should make it clear in the javadoc that addNestedAttributeToProject is adding a 'nested attribute' to the 'attributesToProject' list. Let's make it clear to the customer there is just one list, and let's treat it like one list.
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.
okay.
...rc/test/java/software/amazon/awssdk/enhanced/dynamodb/ProjectionExpressionConvertorTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/software/amazon/awssdk/enhanced/dynamodb/ProjectionExpressionConvertorTest.java
Outdated
Show resolved
Hide resolved
...d/src/test/java/software/amazon/awssdk/enhanced/dynamodb/functionaltests/BasicQueryTest.java
Outdated
Show resolved
Hide resolved
...d/src/test/java/software/amazon/awssdk/enhanced/dynamodb/model/QueryEnhancedRequestTest.java
Outdated
Show resolved
Hide resolved
.addNestedAttributesToProject(NestedAttributeName.create("foo", "bar")) | ||
.attributesToProject(additionalElement) | ||
.build(); | ||
List<String> attributesToProjectStringAttributeOverwrittenNestedLast = Arrays.asList( "foo.bar", "three"); |
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.
See my other comment in the code, I think the 'correct' state here should be "three", and the nested attribute should be overwritten with the others.
Codecov Report
@@ Coverage Diff @@
## master #2035 +/- ##
============================================
+ Coverage 76.61% 77.22% +0.60%
Complexity 225 225
============================================
Files 1113 1136 +23
Lines 33617 34841 +1224
Branches 2600 2726 +126
============================================
+ Hits 25756 26906 +1150
+ Misses 6581 6577 -4
- Partials 1280 1358 +78
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
…ect Enhanced Scan and Enhanced query requests
SonarCloud Quality Gate failed.
|
Add support for bucket ARN parsing for object versioning APIs
Description DDB Enhanced: Added support for Nested objects projection expressions RequestOnPR
Motivation and Context
Fix
EnhancedRequest
Testing
Added JUnit for following casses
1.Projection of a nested Attribute .
2. Projection of a nested Attribute and not nested attribute (using older builder method).
3. Projection of Multiple Attributes
4. Projection of Null attributes passing Null NestedAttributeName --> Returns all elements as per the doc.
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsLicense