Array and map: JSON numbers become float64

Abierto
#12 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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].

Lenguaje dominante
Go
Estrellas
1
Forks
0
Merge medio
1 h 43 min
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tarantool/go-tupleconv

Todos los issues de tarantool/go-tupleconv

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.