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

DynamoDbEnhancedAsyncClient#createTable() fails to generate secondary indexes #5400

Open
tkhill-AWS opened this issue Jul 16, 2024 · 3 comments
Labels
bug This issue is a bug. dynamodb-enhanced p2 This is a standard priority issue

Comments

@tkhill-AWS
Copy link
Contributor

tkhill-AWS commented Jul 16, 2024

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 tkhill-AWS added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 16, 2024
@tkhill-AWS
Copy link
Contributor Author

@debora-ito can confirm the bug.

@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 Jul 16, 2024
@debora-ito
Copy link
Member

debora-ito commented Jul 16, 2024

Support for the sync createTable was added via #4004.

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

@zakerf
Copy link

zakerf commented Dec 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. dynamodb-enhanced p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants