gpt4 book ai didi

java - 使用 dynamodb 映射器将属性投影到索引

转载 作者:行者123 更新时间:2023-12-02 08:44:32 26 4
gpt4 key购买 nike

我只是找不到使用 dynamodb 映射器注释将选定属性(不是哈希键)投影到索引中的方法。

考虑一个例子:

@DynamoDBTable(tableName = "scores")
public class DynaScoreItem {
@DynamoDBHashKey
int user;
@DynamoDBRangeKey
int level;
@DynamoDBAttribute
int score;
@DynamoDBIndexRangeKey(localSecondaryIndexName = "sort_by_added")
long added;
}

我只想将分数添加到“sort_by_added”索引中。如何使用注释来做到这一点?

最佳答案

属性投影是在索引创建时设置的,而不是由注释确定(当前)。无法使用注释将属性标记为属性投影的一部分。查看 Javadoc 中的 DynamoDBMapper.generateCreateTableRequest(Class<?> clazz) :

Parse the given POJO class and return the CreateTableRequest for the DynamoDB table it represents. Note that the returned request does not include the required ProvisionedThroughput parameters for the primary table and the GSIs, and that all secondary indexes are initialized with the default projection type - KEY_ONLY.

其中的关键部分是默认投影类型 - KEY_ONLY。如果您使用此 API 创建表,则必须自己指定投影。

关于java - 使用 dynamodb 映射器将属性投影到索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28941441/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com