我有一个表Book
,其中bookId
和lastBorrowed
分别作为哈希键和范围键。假设每次借书时,都会创建一个新行。
(是的,这还不够,我可以添加一个列来跟踪计数和更新lastBorrowed
日期。但假设我坚持这个设计,我无能为力。)
给定一组bookIds
(或hashKeys
),我希望能够查询每本书最后一次被借阅的时间。
我试图使用QueryRequest
,但不断得到com.amazonaws.AmazonServiceException: Attempted conditional constraint is not an indexable operation
final Map<String, Condition> keyConditions =
Collections.singletonMap(hashKeyFieldName, new Condition()
.withComparisonOperator(ComparisonOperator.IN)
.withAttributeValueList(hashKeys.stream().map(hashKey -> new AttributeValue(hashKey)).collect(Collectors.toList())));
我也尝试过使用BatchGetItemRequest
,但也没有用:
final KeysAndAttributes keysAndAttributes = new KeysAndAttributes() .withConsistentRead(areReadsConsistent);
hashKeys.forEach(hashKey -> { keysAndAttributes.addExpressionAttributeNamesEntry(hashKeyFieldName, hashKey); });
final Map<String, KeysAndAttributes> requestedItemsByTableName = newHashMap();
requestedItemsByTableName.put(tableName, keysAndAttributes);
final BatchGetItemRequest request = new BatchGetItemRequest().withRequestItems(requestedItemsByTableName);
任何建议将不胜感激!或者,如果有人可以告诉我这目前根本不支持,那么我想我会继续前进!