Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data loss when float values are unmarshalled #114

Open
adilansari opened this issue Sep 20, 2022 · 0 comments
Open

Data loss when float values are unmarshalled #114

adilansari opened this issue Sep 20, 2022 · 0 comments

Comments

@adilansari
Copy link
Contributor

adilansari commented Sep 20, 2022

Description

A document having float type of fields may lose precision when using go client.

Steps to reproduce

  • Have a schema with float type of fields and persist 9223372036854775807 as the value for the field.
  • Retrieve (search) the document using multi-search api in Typesense go client and value will be returned as 9223372036854776000
  • This is not reproducible using HTTP API, the value is returned as is

Expected Behavior

  • Value to be returned as is

Actual Behavior

  • Data loss observed when using multi search api

Findings

  • This probably has to do with json unmarshalling the data into map[string]interface{} which by default converts all numbers to float64
  • There is precision loss with default conversion
  • This would probably need custom unmarshalling using json.Number
  • If there is possibility, the Document in SearchResult should be changed map[string]json.RawMessage (or be an addition to existing) to let users implement custom unmarshalling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant