Array and map: JSON numbers become float64

Aperta
#12 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
databases

Direzione di ricerca

Start in converter.go at StringToSliceConverter.Convert and StringToMapConverter.Convert, then read how the number converter parses values. Check the existing tests for array and map conversion behavior. Done means JSON integers retain integer precision and inputs with trailing data such as [1][2] are still rejected.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Reproduction snippets assume:

fac := tupleconv.MakeStringToTTConvFactory()

Where: StringToSliceConverter.Convert (converter.go:258), StringToMapConverter.Convert (converter.go:234).

json.Unmarshal into any decodes every JSON number as float64. So every integer inside an array or map field is stored in Tarantool as a MsgPack double, and integers above 2^53 lose precision.

Reproduction:

arr, _ := fac.GetArrayConverter().Convert(`[1, 12345678901234567891]`)
for _, x := range arr.([]any) {
	fmt.Printf("%T %v\n", x, x)
}
m, _ := fac.GetMapConverter().Convert(`{"id": 1}`)
fmt.Printf("%T\n", m.(map[string]any)["id"])
float64 1
float64 1.2345678901234567e+19
float64

Expected: uint64(1) and uint64(12345678901234567891): integers stay integers, as they do for unsigned/integer/number fields. Integer-ness matters to Tarantool, e.g. for JSON path or multikey index parts typed unsigned/integer over such fields.

Suggested fix: decode with json.Decoder and UseNumber(), then walk the result and convert each json.Number the same way the number converter does (uint64, then int64, then float64 or decimal, see #15). Decoder doesn't reject trailing data by itself, so check that the input is fully consumed to keep the current behavior for inputs like [1][2].

Lingua principale
Go
Stelle
1
Fork
0
Merge medio
1h 43m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tarantool/go-tupleconv

Tutte le issue di tarantool/go-tupleconv

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.