aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

DynamoDB enhanced client - Add "Select" in QueryEnhancedRequest

Open felixchin opened this issue 5 years ago • 14 comments

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 avatar Oct 12 '20 12:10 felixchin

@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.

debora-ito avatar Oct 22 '20 00:10 debora-ito

Any updates on this ?

driverpt avatar Mar 01 '21 11:03 driverpt

"return only the count" functionality would be useful.

RushinNaik avatar Apr 07 '21 07:04 RushinNaik

is this available ?

divyasshanmugam avatar Jun 25 '21 18:06 divyasshanmugam

Any update on this issue?

shivavamsi avatar Aug 08 '21 00:08 shivavamsi

Is there a workaround for this?

mvershinin-chwy avatar Oct 12 '21 17:10 mvershinin-chwy

Have feature to implement?

sanggenOh avatar Dec 28 '21 23:12 sanggenOh

Any workaround found ?

AkramMo avatar Feb 15 '22 19:02 AkramMo

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.

debora-ito avatar Feb 16 '22 23:02 debora-ito

Sad it has been years and this issue has not been resolved yet.

There are two "workarounds":

  1. Implement counting with the classic DynamoDbClient, see example here.
  2. 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()

dimitarz avatar May 16 '23 23:05 dimitarz

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

debora-ito avatar Apr 03 '24 18:04 debora-ito

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.

github-actions[bot] avatar Apr 03 '24 18:04 github-actions[bot]

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.

millems avatar Apr 19 '24 19:04 millems

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.

AndyBette avatar Jun 03 '24 06:06 AndyBette

"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.

debora-ito avatar Oct 14 '24 21:10 debora-ito

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.

github-actions[bot] avatar Oct 14 '24 21:10 github-actions[bot]