我有一个DynamoDB表,其中包含约4.5万条记录,一个主分区键(电子邮件)和一个主排序键(品牌)。所有记录都具有各种属性,一个称为processed
,一个称为studentEmail
。
我需要查找给定学生电子邮件,品牌和经过处理的false
的所有记录,我确信至少要存在一行。
我正在使用以下代码:
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.model.*;
private final AmazonDynamoDB dynamoDB;
public void getRecordForEmailAndBrand(String studentEmail, String brand) {
final Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":studentEmail", new AttributeValue().withS(studentEmail));
expressionAttributeValues.put(":brand", new AttributeValue().withS(brand));
expressionAttributeValues.put(":processed", new AttributeValue().withBOOL(false));
final Map<String, String> attributesNames = new HashMap<>();
attributesNames.put("#p", "processed");
Map<String, AttributeValue> lastKeyEvaluated = null;
List<Map<String, AttributeValue>> rows = new ArrayList<>();
do {
final ScanRequest scanRequest = new ScanRequest()
.withTableName(tableName)
.withFilterExpression("studentEmail = :studentEmail and brand = :brand and #p = :processed")
.withExpressionAttributeNames(attributesNames)
.withExpressionAttributeValues(expressionAttributeValues)
.withExclusiveStartKey(lastKeyEvaluated);
final ScanResult result = dynamoDB.scan(scanRequest);
rows.addAll(result.getItems());
lastKeyEvaluated = result.getLastEvaluatedKey();
} while (lastKeyEvaluated != null);
}
问题在于,碰巧该方法未返回任何行,但是我确定该行在那里,并且可以通过以下事实得到证实:当我使用aws ui时,我可以轻松找到它。我有什么想念的吗?也许在scanRequest中?