I have a DynamoDB table with the following key values: A simple string id as HashKey
and a string representing a Date as RangeKey
. The date string is in YYYY-MM-DD
format.
I am now wondering how DynamoDB orders its entries. When I query for multiple RangeKey
values on the same HashKey
the result is ordered by the date ascending.
However, according to the Dynamo documentation it will order all non-integer RangeKeys considering their UTF-8 byte values.
When I now save the following RangeKey entries:
2019-01-01
2018-12-04
2018-12-05
The output of a simple DynamoDBMapper.query(...)
results in the correct order:
2018-12-04
2018-12-05
2019-01-01
Is Dynamo ordering the RangeKeys by date or is the byte value calculated a way that it matches with the date representation?
Its sorting it in UTF-8 bytes. It has no idea that you are sorting dates, to DynamoDB, its just a string.