DynamoDB enhanced client - Add "Select" in QueryEnhancedRequest
There is no "Select" in QueryEnhancedRequest Builder.
Describe the Feature
Query the Dynamodb and return only the count.
Is your Feature Request related to a problem?
No
Proposed Solution
QueryEnhancedRequest.builder().select(Select select) The select should has those enums
- ALL_ATTRIBUTES
- ALL_PROJECTED_ATTRIBUTES
- SPECIFIC_ATTRIBUTES
- COUNT
Describe alternatives you've considered
Just use QueryRequest instead of QueryEnhancedRequest
Additional Context
- [ ] I may be able to implement this feature request
Your Environment
- AWS Java SDK version used: 2.14.13
- JDK version used: 1.8
- Operating System and version: macOs
@felixchin to confirm, this is mostly to obtain the COUNT number? Because you can specify the attributes to be retrieved from the database in the attributesToProject field.
Any updates on this ?
"return only the count" functionality would be useful.
is this available ?
Any update on this issue?
Is there a workaround for this?
Have feature to implement?
Any workaround found ?
No updates here other than this is in our backlog.
As a reminder, please add a 👍 reaction in the original description of the issue to show interest, it helps us prioritizing all the feature requests we have.
Sad it has been years and this issue has not been resolved yet.
There are two "workarounds":
- Implement counting with the classic DynamoDbClient, see example here.
- You can still use the Enhanced client by projecting a property that doesn't exist. This will return a null for each object. Then count the nulls in the returned list. Not super optimal but it works.
var count = 0
index.query(
QueryEnhancedRequest.builder()
.queryConditional(QueryConditional.keyEqualTo(key))
.attributesToProject("COUNT")
.build(),
).subscribe {
count += it.items()?.size ?: 0
}.await()
Sorry for the late update:
"count" was released in SDK version 2.20.153 (via https://github.com/aws/aws-sdk-java-v2/pull/4444).
Page now exposes count, scanned count and consumed capacity - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/Page.html
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.
Reopening because while the SDK supports returning the count field, it doesn't support specifying the select parameter on the query request. This means that items still need to be retrieved from the service just to get the count.
The only workarounds available at this time are to use an execution interceptor that adds the setting to the request, or to use the low-level client to retrieve the count.
The most efficient option is probably to use select via the low-level client to get the count. To minimize the amount of data transferred when using the enhanced client for count specifically, project none of the attributes of the item when scanning or querying.
The DynamoDB service team is tracking internally the feature request to add the rest of the select functionality to the enhanced client.
"Select" is now supported in QueryEnhancedRequest (released in version 2.26.25) and ScanEnhancedRequest (released in version 2.27.19). This includes the "SELECT(COUNT)" option.
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.