aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

DynamoDbEnhancedAsyncClient#createTable() fails to generate secondary indexes

Open tkhill-AWS opened this issue 1 year ago • 2 comments

Describe the bug

DynamoDbEnhancedAsyncClient#createTable() fails to generate secondary indexes that are defined on annotations of the POJO class.

Expected Behavior

The sync version of the DynamoDB enhanced client does create secondary indexes as defined on the POJO class, and so should the async version.

As noted in the Java SDK Developer Guide, beginning with version 2.20.86, createTable() should automatically generate secondary indexes from data class annotations.

Current Behavior

If i run this:

            createTableFuture = messageThreadTable.createTable( );

where the following class was used for schema generation:

Click to see the DynamoDbBean
package org.example.ddbec.model;

import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSecondaryPartitionKey;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSecondarySortKey;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey;

import java.util.List;

@DynamoDbBean
public class MessageThread {
    private String forumName;
    private String subject;
    private String message;
    private String lastPostedBy;
    private String lastPostedDateTime;
    private Integer views;
    private Integer replies;
    private Integer answered;
    private List<String> tags;

    @DynamoDbPartitionKey
    public String getForumName() {
        return forumName;
    }

    public void setForumName(String forumName) {
        this.forumName = forumName;
    }

    // Sort key for primary index and partition key for GSI "SubjectLastPostedDateIndex".
    @DynamoDbSortKey
    @DynamoDbSecondaryPartitionKey(indexNames = "SubjectLastPostedDateIndex")
    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    // Sort key for GSI "SubjectLastPostedDateIndex" and sort key for LSI "ForumLastPostedDateIndex".
    @DynamoDbSecondarySortKey(indexNames = {"SubjectLastPostedDateIndex", "ForumLastPostedDateIndex"})
    public String getLastPostedDateTime() {
        return lastPostedDateTime;
    }

    public void setLastPostedDateTime(String lastPostedDateTime) {
        this.lastPostedDateTime = lastPostedDateTime;
    }
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getLastPostedBy() {
        return lastPostedBy;
    }

    public void setLastPostedBy(String lastPostedBy) {
        this.lastPostedBy = lastPostedBy;
    }

    public Integer getViews() {
        return views;
    }

    public void setViews(Integer views) {
        this.views = views;
    }

    @DynamoDbSecondaryPartitionKey(indexNames = "ForumRepliesIndex")
    public Integer getReplies() {
        return replies;
    }

    public void setReplies(Integer replies) {
        this.replies = replies;
    }

    public Integer getAnswered() {
        return answered;
    }

    public void setAnswered(Integer answered) {
        this.answered = answered;
    }

    public List<String> getTags() {
        return tags;
    }

    public void setTags(List<String> tags) {
        this.tags = tags;
    }

    public MessageThread() {
        this.answered = 0;
        this.lastPostedBy = "";
        this.forumName = "";
        this.message = "";
        this.lastPostedDateTime = "";
        this.replies = 0;
        this.views = 0;
        this.subject = "";
    }

    @Override
    public String toString() {
        return "MessageThread{" +
                "forumName='" + forumName + '\'' +
                ", subject='" + subject + '\'' +
                ", message='" + message + '\'' +
                ", lastPostedBy='" + lastPostedBy + '\'' +
                ", lastPostedDateTime='" + lastPostedDateTime + '\'' +
                ", views=" + views +
                ", replies=" + replies +
                ", answered=" + answered +
                ", tags=" + tags +
                '}';
    }
}

no secondary index are generated:

image

Reproduction Steps

(See above)

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.26.6

JDK version used

17

Operating System and version

Mac - Sonoma 14.5

tkhill-AWS avatar Jul 16 '24 13:07 tkhill-AWS

@debora-ito can confirm the bug.

tkhill-AWS avatar Jul 16 '24 13:07 tkhill-AWS

Support for the sync createTable was added via https://github.com/aws/aws-sdk-java-v2/pull/4004.

This is the same ask, but for the async client.

debora-ito avatar Jul 16 '24 18:07 debora-ito

@debora-ito this PR might be relevant to this #5615

zakerf avatar Dec 13 '24 09:12 zakerf

Fixed released in version 2.31.58.

debora-ito avatar Jun 09 '25 21:06 debora-ito

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jun 09 '25 21:06 github-actions[bot]