DynamoDB: add support for transactional writes that include update operations with custom update and condition expressions #3294
+458
−53
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.
Description
DynamoDB transactional writes that are created using the document model or the object model can now include update operations with custom update and condition expressions:
AddKeyToUpdate
methods have been added to theDocumentTransactWrite
class. The methods enable adding an update operation to the transaction with an arbitrary update expression instead of providing aDocument
.TransactWriteItemOperationConfig
can also include a condition expression, theAddKeyToUpdate
call can include both an update expression and a condition expression. This enables conflicts to occur between the two expressions if they use the same parameter names for attribute names and/or values. If both expressions contain the same parameter, but with different values, an exception is thrown.AddSaveKey
methods have been added to theTransactWrite
class. The methods enable adding a save operation with an arbitrary update expression instead of providing an object. Optionally, a condition expression can be provided because due to the lack of object, no version check can occur. This also enables more complex condition expressions than the simple version check.AddDeleteKey
methods now include an optional parameter for the condition expression. This is comparable to the same parameter of theAddSaveKey
methods and is added for symmetry.Motivation and Context
The new operations are useful in scenarios when an item needs to be updated without retrieving it first. This can help avoid conflicts in some cases.
Example scenario:
DynamoDB update expressions can be used to increment a value by a given amount (e.g
SET counter = counter + 1
). Using an update expression without needing to use low-level operations is possible with the changes in this PR.The example above can be implemented by using a transaction that includes the an operation that adds the new item and an update operation with an update expression that increments the counter and a condition expression that checks that the counter cannot surpass the limit.
Testing
Existing DynamoDB integration tests have been extended to test the new operations for both models. All tests passed.
Types of changes
Checklist
License