Skip to content
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… #2030

Closed
wants to merge 1 commit into from
Closed

Conversation

joviegas
Copy link
Contributor

Description DDB Enhanced: Added support for Nested objects projection expressions BugReportLink

Motivation and Context

Root Cause

  • BugReportLink Didnot support the nested queries
  • DDB expects the DOT or special characters as Expression.
  • Support for expression was not initially provided by implementing "attributeToProject"

Fix

  • In order to pass nested attribs we need to mention the attributesToProject as DOT, we need to create expressions seperated by DOTS.
  • Refer developerguide-Link for more details.

Why have we created a new parameter called attributesToProjectExpressionNames and not used expressionAttributeNames of software.amazon.awssdk.services.dynamodb.model.QueryRequest ?

  • The expressionAttributeNames of QueryRequest is internally used for Filter Expression in QueryConditional in QueryEnhancedRequest. We cannot expose this directly as a part pf QueryEnhancedRequest parameters. Thus we have provided a decicated name map for parameters used in attributesToProject.

Testing

  • Connected to DDb and tested for Nested attributes
  • Junit for Single Nested Attribute projection
attributesToProjectExpressionNames (("#attribOne", "attribOne") , "#attribOne", "attribOne");
attributesToProject("#inner.#attribOne")

  • Junit for Multiple Nested Attribute projection and one outer Atrribute
attributesToProjectExpressionNames (("#inner", "innerAttributeRecord") , "#attribOne", "attribOne");
attributesToProject(#inner.#attribOne","outerAttribOne","#inner.attribTwo")

  • Junit for Attribute that doenot exsist
attributesToProjectExpressionNames (("#nonExistent", "nonExistentSlot") ;
attributesToProject("#nonExistent")

  • Junit for Empty expression name Map
attributesToProjectExpressionNames ( new HashMap<>()) ;
attributesToProject("innerAttributeRecord")

This case is same as attributesToProjectExpressionNames not specified or null.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas joviegas requested review from dagnir and bmaizels September 10, 2020 22:09
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 4 Code Smells

78.4% 78.4% Coverage
4.7% 4.7% Duplication

warning The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

Copy link
Contributor

@dagnir dagnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BugReportLink is this supposed to point to an issue? Just takes me too a PR/commit :). Interested in seeing the original bug report if there is one

private static boolean isAttributeToProjectAnExpression(final String attr,
final Map<String, String> projectExpressionNamesMap) {
return projectExpressionNamesMap != null
&& projectExpressionNamesMap.keySet().stream().filter(key -> attr.contains(key)).findAny().isPresent();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this expression be replaced with Map#containsKey?

@@ -56,6 +56,12 @@ private ScanOperation(ScanEnhancedRequest request) {
return new ScanOperation<>(request);
}

private static boolean isAttributeToProjectAnExpression(final String attr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider extracting to a utility class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing the Pull request without merge as will use other user friendly approach.

@joviegas joviegas closed this Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants