aws / aws/aws-sdk-java-v2

DynamoDB Autogenerated Update Expression Is Too Large

Open
#4,597 6 comments 4 reactions 0 assignees View on GitHub
dynamodb-enhanced feature-request p2
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

### Describe the bug

When generating update expressions via enhanced client tables, every name and value in the name and value maps are set to the name of their corresponding field prefixed by `"AMZN_MAPPED_"`. This causes problems when the number of attributes grows large. Changing the names of the fields on the class is not a suitable solution because it breaks readability of the code. Further, changing the names of the attributes in the dynamo table is not a suitable solution because that will require refactoring all services that interact with the table and may require migrating the table.

Consider the class below:

```
@Data
@DynamoDbBean
@NoArgsConstructor
@AllArgsConstructor
public class MyBean {
@Getter(onMethod_ = @DynamoDbPartitionKey)
private int id;
private String stringField;
private Integer integerField;
}
```

### Expected Behavior

Performing an `updateItem` on a `DynamoDbTable` with an instance of `MyBean` results in the following, minified update expression:

`SET #n0 = :v0, #n1 = :v1`

with a name map:

`#n0 -> stringField, #n1 -> integerField`

and with a value map:

`:v0 -> , :v1 -> `

### Current Behavior

Performing an `updateItem` on a `DynamoDbTable` with an instance of `MyBean` results in the following update expression, which is too large in some applications:

`SET #AMZN_MAPPED_stringField = :AMZN_MAPPED_stringField, #AMZN_MAPPED_integerField = :AMZN_MAPPED_integerField`

with a name map:

`#AMZN_MAPPED_stringField -> stringField, #AMZN_MAPPED_integerField -> integerField`

and with a value map:

`:AMZN_MAPPED_stringField -> , :AMZN_MAPPED_integerField -> `

### Reproduction Steps

Create a `DynamoDbBean` with a large number of fields. Create an instance of that bean. Perform a update item request using a `DynamoDbTable` from the enhanced client. The size of the item may be well within the limits of DynamoDB, but the update expression is too large to properly update it.

### Possible Solution

Minify the names of fields when creating the update expression.

### Additional Information/Context

I'm filing this as a bug since it's technically possible for this to break production code given that one is using the ignoreNulls option if some of null values on the bean are set for the first time. If this is better suited for a feature request, let me know and I will recreate it as such.

### AWS Java SDK version used

2.20.157

### JDK version used

Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190

### Operating System and version

Windows 10 Home - 22H2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.