0

So I am using Pagination with the latest DynamoDBEnhancedAsyncClient.

However while applying the limit() on the QueryEnhancedRequest its not limiting the items on a single page. Example: if I pass limit(1) still its showing 2 records in the result. Not sure if the limit() takes number of items as the parameter or the number of pages. If its pages, is there any way to limit the number of items per page? We know that DDB creates pages with max size of 1MB. but our json records have size in bytes, which means that 1000s of records will be fetched per page. Isn't this inefficient? Is it possible to limit the items per page?

ghostrider
  • 2,046
  • 3
  • 23
  • 46
  • 1
    Can you please add some demo code? – Ermiya Eskandary May 24 '22 at 14:55
  • You can typically [supply an item limit](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.Limit) when using Query. – jarmod May 24 '22 at 14:56
  • Does this answer your question? [Limit method in QueryEnhancedRequest for DynamoDB Java v2 sdk doesn't limit as expected](https://stackoverflow.com/questions/62417472/limit-method-in-queryenhancedrequest-for-dynamodb-java-v2-sdk-doesnt-limit-as-e) – Ermiya Eskandary May 24 '22 at 15:37
  • The decision to use limit as the option name, while it does not actually match what limit typically does across other AWS SDKs, is very weird and confusing. But the above question should answer your question – Ermiya Eskandary May 24 '22 at 15:38
  • 1
    Actually, that client does not actually seem to limit the item fetched via the API but just using Java methods... I'd just go with the normal async client. The enhanced client is really for creating/modifying tables not dealing with data tbh. – Ermiya Eskandary May 24 '22 at 15:40
  • @ErmiyaEskandary thanks a lot!!! My usecase involves querying using GSI and pagination. Do you suggest switching to the other DynamoAsyncClient for the same? What are your views – ghostrider May 24 '22 at 20:04
  • 1
    @ghostrider yes I would recommend switching. This client is enhanced only for some use cases. – Ermiya Eskandary May 24 '22 at 20:18
  • The enhanced client is quite verbose and confusing. I hope the usual async client is comparatively easy for indexes and pagination – ghostrider May 24 '22 at 20:27

1 Answers1

1

According to the documentation, it is not limiting the number items in the results.

The documentation says: Note:The limit does not refer to the number of items to return, but how many items the database should evaluate while executing the query. Use limit together with Page.lastEvaluatedKey() and exclusiveStartKey in subsequent query calls to evaluate limit items per call. Here is the link

Tech Gun
  • 29
  • 1
  • So limit(1) should evaluate 1 item and return at most 1 item, but that does not match what the OP is saying. I think we need to see the OP's code here. – jarmod May 24 '22 at 15:25
  • thanks a lot!!! My usecase involves querying using GSI and pagination. Do you suggest switching to the other DynamoAsyncClient for the same? What are your views – ghostrider May 24 '22 at 20:05