aws-sdk-java
aws-sdk-java copied to clipboard
Scanning with returnConsumedCapacity returns PaginatedScanList which does not surface consumedCapacity
Describe the bug
I am using DynamoDBMapper.scan(Class<T>, DynamoDBScanExpression)
which returns a PaginatedScanList
. When I create the scan expression, if I set returnConsumedCapacity
, there is no way to get the value of the consumed capacity because it is hidden in a private field and not surfaced.
Expected behavior
I expected that I would be able to read consumedCapacity
from the result of the scan.
Current behavior
The result of the scan is hidden in a private variable and consumedCapacity
is not surfaced. If I debug and look at private variables, I can see the consumed capacity is set:
Steps to Reproduce
val scanExpression = DynamoDBScanExpression()
.withFilterExpression("<my filter>")
.withReturnConsumedCapacity(ReturnConsumedCapacity.INDEXES)
val scanResponse = this.ddbMapper.scan(CaDefinitionModel::class.java, scanExpression)
val consumedCapacity = scanResponse.scanResult.consumedCapacity
Possible Solution
I think the PaginatedScanList
class should surface a consumedCapacity
property which returns the sum of consumedCapacity
from each scanResult
fetched. So, the total consumed capacity thus far would be returned.
Context
I wanted to report on consumed capacity for a job I am writing so we can estimate costs.
AWS Java SDK version used
aws-java-sdk-dynamodb-1.12.131.jar
JDK version used
openjdk version "11.0.9" 2020-10-20 / OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11) / OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode)
Operating System and version
MacOS Monterey 12.1
Hi @christi-square thank you for reaching out.
We had a pretty similar request (https://github.com/aws/aws-sdk-java/issues/1170) for load, save and delete item. We ended up implementing those in the Java SDK v2 DynamoDB Enhanced Client, not in the V1 DynamoDB Mapper.
This request will probably have the same path, since we are prioritizing work for SDK V2. Scan does not return consumedCapacity currently, so it would be a feature request too.
Let us know if you'd like to open a feature request in Java SDK v2 for this.
Hmm, I didn't realize there was a v2. Yes, that would be great if you could open a ticket there. I don't know when I'll be able to upgrade to v2 to get sample code but if I can manage it soon, I will provide an example.