Skip to content

DynamoDB Autogenerated Update Expression Is Too Large #4597

Open
@DaltonWorsnup

Description

@DaltonWorsnup

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<MyBean> 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 -> <value of stringField>, :v1 -> <value of integerField>

Current Behavior

Performing an updateItem on a DynamoDbTable<MyBean> 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 -> <value of stringField>, :AMZN_MAPPED_integerField -> <value of 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dynamodb-enhancedfeature-requestA feature should be added or improved.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions