简体   繁体   English

扫描DynamoDB表未返回数据

[英]Scan DynamoDB table is not returning data

I am trying to scan failed token counts from dynamodb database table without any indexes. 我正在尝试从dynamodb数据库表中扫描失败的令牌计数,而没有任何索引。 It is returning 0 from the database. 它从数据库返回0。 I doubt it is not scanning complete database. 我怀疑它没有扫描完整的数据库。 Below is my method and the dynamoDBClient working condition one and it has connection details. 下面是我的方法和dynamoDBClient工作条件之一,它具有连接详细信息。 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? 我的要求出了什么问题?

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. 扫描时,您必须继续使用先前的LastEvaluatedKey作为下一个请求的ExclusiveStartKey来重新提交请求,直到您在响应中不再收到LastEvaluatedKey

Your first request is only evaluating the first ScannedCount: 1456 items in the table (≈ 1MB of data). 您的第一个请求仅评估表中的第一个ScannedCount: 1456项( ScannedCount: 1456数据)。

See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.Pagination 参见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. 由于可用的底层API,DynamoDB使这一点更加明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM