aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.17k stars 840 forks source link

DynamoDB enhanced client - Add "Select" in QueryEnhancedRequest #2083

Open felixchin opened 3 years ago

felixchin commented 3 years ago

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

Describe alternatives you've considered

Just use QueryRequest instead of QueryEnhancedRequest

Additional Context

Your Environment

debora-ito commented 3 years ago

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

driverpt commented 3 years ago

Any updates on this ?

RushinNaik commented 3 years ago

"return only the count" functionality would be useful.

divyasshanmugam commented 3 years ago

is this available ?

shivavamsi commented 3 years ago

Any update on this issue?

mvershinin-chwy commented 2 years ago

Is there a workaround for this?

sanggenOh commented 2 years ago

Have feature to implement?

AkramMo commented 2 years ago

Any workaround found ?

debora-ito commented 2 years ago

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.

dimitarz commented 1 year ago

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()
debora-ito commented 6 months ago

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

github-actions[bot] commented 6 months ago

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.

millems commented 5 months ago

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.

AndyBette commented 4 months ago

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.