gpt4 book ai didi

java - java中的batchGetItem API错误

转载 作者:搜寻专家 更新时间:2023-10-31 19:41:03 25 4
gpt4 key购买 nike

我正在查询的实体有一个 HashKey 和一个 RangeKey(数字)。当我在其上使用 batchGetItem 时,出现以下错误:

AWS Error Code: ValidationException, AWS Error Message: One or more parameter values were invalid: Mismatching attribute types between location and schema

架构:

Table: Daily

Hash Key: CustId (String)

Range Key: Dated (Number)

数据:

CustId : VisioNerdy

Dated : 1329071400000

代码:

  List<Key> fkeys = new ArrayList<Key>(); //tableName="Daily", keys=["VisioNerdy"], ranges=[1329071400000]
Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
for(int i = 0; i < keys.size(); i++)
{
String key = keys.get(i);
if(ranges == null)
fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key)));
else
fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))
.withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString())));
}
requestItems.put(tableName, new KeysAndAttributes().withKeys(fkeys));
BatchGetItemRequest batchGetItemRequest = new BatchGetItemRequest().withRequestItems(requestItems);
BatchGetItemResult result = client.batchGetItem(batchGetItemRequest);

有什么线索吗?

最佳答案

您已经定义了 Hash and Range Type Primary Key 的范围属性作为Number 类型,但通过withS() 为您的请求准备其属性值作为String 类型:

fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))
.withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString())));

改变 withS(String s)withN(String s)应该相应地解决您的问题(令人困惑的是,这两种方法都需要 String 类型的参数):

fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))
.withRangeKeyElement(new AttributeValue().withN(ranges.get(i).toString())));

诚然,DynamoDB data types 的隐式弱类型仅基于 String 参数提交并不能完全简化开发 ;)

关于java - java中的batchGetItem API错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254838/

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