I am using AWS SDK2 DynamoDB for an application with the following schema:
personId startDate endDate name age job
1 10/2/2013 10/3/2020 Bob 12 SWE
1 8/2/2013 10/3/2021 Bob 12 EE
2 10/2/2013 10/3/2021 Joe 17 Student
3 11/2/2013 10/3/2022 Kim 16 Boss
My goal is to be able to query the table by a personId and a date in order to retrieve a person object. Currently, I am thinking about having a partition key on personId; however, I am not sure how to design my sortKey.
For example, say I want a person with personId = 1 and date = 10/5/2019, I would expect the first and second entry of the example table to be returned because the date is between the startDate and endDate. How can I design the sortKey so that I can use an appropriate key condition expression to say something like date between startDate and endDate? I know that filter expression can be used, but I was wondering if there was a way to design the sort key so that filter is not needed as it is more costly.