Given a DynamoDB table with a partition key id
and sort key date_epoch
.
I'll have items like this:
id | date_epoch
-----------------
1 | 1535961978
2 | 1535961996
1 | 1535962033
2 | 1535962055
3 | 1535962064
5 | 1535962073
1 | 1535962080
2 | 1535962085
For each given unique id
, I only want its most recent item. So from this sample data, I only want the following results:
id | date_epoch
-----------------
3 | 1535962064
5 | 1535962073
1 | 1535962080
2 | 1535962085
I can figure out how to do this with very ugly code. I've gotten each unique id
, then iterated over each individual id
and gotten only the most recent item .withScanIndexForward(false)
and .withMaxResultSize(1)
(as shown in this example and this example), but it seems like there must be a better way to do this.
Can we set a scan filter to limit the max items or something else I haven't thought of?