gpt4 book ai didi

java - ExpressionAttributeNames 中提供的值在表达式中未使用 : keys | DynamoDB Java SDK

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:28 24 4
gpt4 key购买 nike

我正在尝试根据一些过滤器从 DynamoDB 获取数据。 (例如:给我一条产品编号和颜色编号为“A”、“B”的记录。)以下是代码片段:

AmazonDynamoDB amazonDynamoDB = DynamoDBClient.getInstance().getConnection();
Map<String, HashMap<String, String>> attrVal = new HashMap<String, HashMap<String, String>>();

Map<String,String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#colorwayNumber","colorwayNumber");
expressionAttributesNames.put("#productNumber","productNumber");

Map<String,AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":colorwayNumber",new AttributeValue().withS(colorwayID));
expressionAttributeValues.put(":productNumber",new AttributeValue().withS(productNumber));

QueryRequest queryRequest = new QueryRequest()
.withTableName(ConverseConstants.PLM_PRODUCT_TABLE)
.withKeyConditionExpression("#colorwayNumber = :colorwayNumber")
.withKeyConditionExpression("#productNumber = :productNumber")
.withExpressionAttributeNames(expressionAttributesNames)
.withExpressionAttributeValues(expressionAttributeValues);

QueryResult queryResult1 = amazonDynamoDB.query(queryRequest);


List<Map<String, AttributeValue>> results1 = queryResult1.getItems();

以下是异常(exception)情况:

Caused by: com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: Value provided in ExpressionAttributeNames unused in expressions: keys: {#colorwayNumber} (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException;

希望我提供了足够的信息。谢谢!

最佳答案

问题似乎出在这里:

.withKeyConditionExpression("#colorwayNumber = :colorwayNumber")
.withKeyConditionExpression("#productNumber = :productNumber")

在这里,您用第二个表达式 (#productNumber = :productNumber) 覆盖第一个表达式 (#colorwayNumber = :colorwayNumber)。这样,表达式中实际上未使用 colorwayNumber

关于java - ExpressionAttributeNames 中提供的值在表达式中未使用 : keys | DynamoDB Java SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58660794/

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