Aws-sdk-java: DynamoDB: getTotalCount is 0 for .withSelect(Select.COUNT)

Created on 27 Apr 2016  路  5Comments  路  Source: aws/aws-sdk-java

   val spec = new QuerySpec()
      ....
      .withSelect(Select.COUNT)

   val result = index.query(spec)
   result.getTotalCount

Above code returns 0

only after iterating through the result the return value is correct

I realize getTotalCount returns the total count accumulated so far. I would think the behavior for the .withSelect(Select.COUNT) would be different.

Overall I find the name getTotalCount missleading; it might be better as getTotalAccumulatedCount

Most helpful comment

Hi, I'm seeing the same issue and found this quite confusing. What _is_ the correct way to get the total count of matching items for a query? I have code very similar to @neil-rubens' above.

All 5 comments

The behavior is clearly documented.

https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-dynamodb/src/main/java/com/amazonaws/services/dynamodbv2/document/ItemCollection.java#L151-L156

I understand that name seems to be confusing. Unfortunately we cannot remove this as it a breaking change. I will go ahead and deprecate the current method and add a new method.

Thanks for the quick reply. On a second thought adding a getTotalAccumulatedCount might further reinforce confusion about specifics of getTotalCount; so am not sure what would be a good fix in this situation.

I have created an issue in our internal backlog for tracking this for our next major version. I am fine with adding a new method and marking the existing getTotalCount as deprecated and also improving the java doc on the existing method. This has to be done at some point because we cannot drop the support for this method.

I have staged this for our next release tentatively scheduled for tomorrow.

Hi, I'm seeing the same issue and found this quite confusing. What _is_ the correct way to get the total count of matching items for a query? I have code very similar to @neil-rubens' above.

Was this page helpful?
0 / 5 - 0 ratings