问题
I am trying to scan failed token counts from dynamodb database table without any indexes. It is returning 0 from the database. I doubt it is not scanning complete database. Below is my method and the dynamoDBClient
working condition one and it has connection details. I am posting here only the scan query part
public int getFailedAuthStatusCount() {
Map<String,String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#status","auth_status");
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val", new AttributeValue().withS("FAIL"));
ScanRequest scanRequest = new ScanRequest()
.withTableName("Token")
.withFilterExpression("#status = :val")
.withExpressionAttributeNames(expressionAttributesNames)
.withExpressionAttributeValues(expressionAttributeValues);
ScanResult scanResult = dynamoDBClient.scan(scanRequest); //client is working fine.
return scanResult.getCount();
}
Here is the response.
{Items: [],Count: 0,ScannedCount: 1456,LastEvaluatedKey: {GUID={S: 0c4b281e6f9290c0fb3bf13f28c88fd,}, VENDOR={S: DELL,}},}
what is wrong with my request?
回答1:
Nothing is wrong with your request. When scanning, you have to continue resubmitting the request with the prior LastEvaluatedKey
as the next request's ExclusiveStartKey
until you no longer receive a LastEvaluatedKey
in the response.
Your first request is only evaluating the first ScannedCount: 1456
items in the table (≈ 1MB of data).
See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.Pagination
Table scans are slow and expensive in all database environments. That's a key reason why indexes are important. DynamoDB makes this more apparent because of the low-level API that's available.
来源:https://stackoverflow.com/questions/53641296/scan-dynamodb-table-is-not-returning-data