InstantAsStringAttributeConverter does not appear to have lexicographically correct sorting as claimed
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 2.6k
- Fork
- 1k
- Merge medio
- 2g 9h
- PR unite (30g)
- 51
Descrizione
Describe the bug
InstantAsStringAttributeConverter claims that its provided serialization is lexicographically sortable given that the year of the Instant is non-negative. It seems to also not be lexicographically sortable if any value falls directly on a second, since InstantAsStringAttributeConverter simply calls toString(), which uses an adapting ISO 8601 formatter that will truncate 3-groups of zero values:
From Instant's toString():
The format used is the same as DateTimeFormatter.ISO_INSTANT.
From DateTimeFormatter's ISO_INSTANT:
The nano-of-second outputs zero, three, six or nine digits as necessary.
The manifestation of this problem was a query on a sort key that, when re-sorted in application code, changed its order.
Expected Behavior
When using an Instant as a sort key on a DynamoDbBean, I expect sort orderings like this to be returned by a query:
2020-12-23T07:05:28.991Z
2020-12-23T07:05:29Z
2020-12-23T07:05:29.017Z
Current Behavior
Instead I'm getting orderings like this:
2020-12-23T07:05:28.991Z
2020-12-23T07:05:29.017Z
2020-12-23T07:05:29Z
since Z comes after . lexicographically. This disagrees with the natural sort order of the corresponding Instants.
Steps to Reproduce
Create a Dynamo schema with a string sort key, write two instants that share a second, but ensure one of them falls directly on the second while the other has some fractional component.
Possible Solution
Use new DateTimeFormatterBuilder().appendInstant(9).toFormatter() to control the number of zeros. For any values taken from System.currentTimeMillis() there will be a lot of unnecessary zeros, but I don't think there's any other correct default behavior.
Context
It's nice to combine the enhanced client's ability to use native Java types with querying by time. In this case the workaround is pretty straightforward for my case.
Your Environment
- AWS Java SDK version used: 2.15.50
- JDK version used: 11
- Operating System and version: Mac OS X 10.15.7
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Parti da InstantAsStringAttributeConverter e verifica come serializza i valori Instant tramite toString(). Riproduci il caso con una chiave di ordinamento string e due istanti che condividono lo stesso secondo, di cui uno con un valore frazionario; il lavoro è completato quando le stringhe serializzate preservano l’ordinamento naturale di Instant durante la query e un nuovo ordinamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- aws, java
- Ambito
- database
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100