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

DynamoDb enhanced client: support UpdateExpressions in single-request update #5554

Open
2 tasks
IDUN-BogdanPi opened this issue Sep 4, 2024 · 2 comments
Open
2 tasks
Labels
dynamodb-enhanced feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@IDUN-BogdanPi
Copy link

Describe the feature

Enhance the UpdateItemEnhancedRequest to support update expressions.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html

I see this feature is partially implemented: https://aws.amazon.com/blogs/developer/using-atomic-counters-in-the-enhanced-dynamodb-aws-sdk-for-java-2-x-client/

but as it is also stated in the article:

Update expressions in the extensions are applicable for use cases where you want to do the same thing with an attribute every time that you call the database, such as atomic counters. However, if you need a one-time effect for a single request, then leveraging the extension framework isn’t useful.

Use Case

I need to atomically increment a numeric value in a table column by different amounts on demand, without first reading the current value.

Consider this table:

@Getter
@Setter
@DynamoDbBean
public class Recording {

    private String id;
    private Long totalRecordingSeconds;

I need to be able to update and increment the value of totalRecordingSeconds with different durations: +30, + 20 ... etc, without reading the current value.

It would be helpful to be able to perform something like:

        String updateExpression = "SET totalRecordingSeconds = if_not_exists(totalRecordingSeconds, :zero) + :increment";
        
        Map<String, AttributeValue> expressionValues = new HashMap<>();
        expressionValues.put(":increment", AttributeValue.builder().n(Long.toString(incrementBy)).build());
        expressionValues.put(":zero", AttributeValue.builder().n("0").build());

        Expression expression = Expression.builder()
                .expression(updateExpression)
                .expressionValues(expressionValues)
                .build();


        UpdateItemEnhancedRequest<Recording> request = UpdateItemEnhancedRequest.builder(Recording.class)
                .key(k -> k.partitionValue(id))  
                .updateExpression(expression)   
                .build();


        table.updateItem(request);

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Java SDK version used

2.21.37

JDK version used

22.0.2

Operating System and version

MacOS Sonoma 14.5

@IDUN-BogdanPi IDUN-BogdanPi added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 4, 2024
@debora-ito
Copy link
Member

PR #3836 started working on this but it lost traction. I'll see if I can get it moving again.

@debora-ito debora-ito added dynamodb-enhanced p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Sep 4, 2024
@IDUN-BogdanPi
Copy link
Author

Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamodb-enhanced feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants