derjust / spring-data-dynamodb

This module deals with enhanced support for a data access layer built on AWS DynamoDB.
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
403 stars 141 forks source link

@Query annotation to support query limiting #226

Closed boostchicken closed 5 years ago

boostchicken commented 5 years ago

This will allow you to limit the results returned from a DynamoDB query that has a sort and range key, techincally also a Scan. I developed this to reduce cost b ased on the new OnDemand pricing.

Example:

@Query(limit = "10")
List<Blah> findFirst10ByStatusAndDateTimeBeforeOrderByDateTimeDesc(String Status, String DateTime);

The previous behavior would actually return every single result and then clip it. With this limit parameter dynamo only returns the request amount of results. This is mainly for HashAndRange. It still requires First10 and the Query annotation to work otherwise the Spring-DynamoDB will just do queries limited to 10 results until it gets them all.

boostchicken commented 5 years ago

image

A little look at how my query results return look based on this now. Also usage metrics are way down.

codecov-io commented 5 years ago

Codecov Report

Merging #226 into master will increase coverage by 0.05%. The diff coverage is 73.91%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #226      +/-   ##
============================================
+ Coverage     67.31%   67.36%   +0.05%     
- Complexity      656      658       +2     
============================================
  Files            83       83              
  Lines          2227     2246      +19     
  Branches        392      393       +1     
============================================
+ Hits           1499     1513      +14     
- Misses          549      553       +4     
- Partials        179      180       +1
Impacted Files Coverage Δ Complexity Δ
.../repository/support/DynamoDBEntityInformation.java 50% <ø> (ø) 1 <0> (ø) :arrow_down:
...y/query/DynamoDBEntityWithHashKeyOnlyCriteria.java 69.04% <100%> (+0.75%) 13 <0> (ø) :arrow_down:
...namodb/repository/query/PartTreeDynamoDBQuery.java 85.71% <100%> (ø) 10 <0> (ø) :arrow_down:
...epository/query/AbstractDynamoDBQueryCriteria.java 68.46% <100%> (+0.38%) 101 <1> (+1) :arrow_up:
...ynamodb/repository/query/DynamoDBQueryCreator.java 75% <100%> (+3.57%) 2 <1> (ø) :arrow_down:
...ery/DynamoDBEntityWithHashAndRangeKeyCriteria.java 74.3% <100%> (+0.14%) 74 <0> (ø) :arrow_down:
...db/repository/query/DynamoDBCountQueryCreator.java 44.44% <50%> (ø) 2 <1> (ø) :arrow_down:
...port/DynamoDBIdIsHashKeyEntityInformationImpl.java 72.72% <50%> (-2.28%) 9 <0> (ø)
...amoDBIdIsHashAndRangeKeyEntityInformationImpl.java 84% <50%> (-2.96%) 16 <0> (ø)
...repository/query/AbstractDynamoDBQueryCreator.java 49.05% <50%> (+0.03%) 11 <0> (ø) :arrow_down:
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bbc97ec...958236c. Read the comment docs.

boostchicken commented 5 years ago

image

A look at GSI read metrics after deployment.

derjust commented 5 years ago

Thank you so much. Merged via #239