[CDRIVER-4725] Fetching data decimal data from CLOB looses precision Created: 15/Sep/23 Updated: 27/Oct/23 Resolved: 17/Oct/23 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | BSON |
| Affects Version/s: | 1.21.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | arun mr | Assignee: | Kevin Albertson |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
| Comments |
| Comment by Kevin Albertson [ 17/Oct/23 ] | |||||||||||||||||
Parsing the JSON non-integer literals is expected to parse as double
The precision is limited to what a double can store. If retaining the precision is needed, consider updating the JSON to store the value as a string or Decimal128 to retain the precision. Issue is being closed since this does not appear to be a bug in the driver. | |||||||||||||||||
| Comment by arun mr [ 17/Oct/23 ] | |||||||||||||||||
|
Thanks Kevin. The type we are getting for this data "a" is 'BSON_TYPE_DOUBLE' . So we can't use bson_iter_decimal128. | |||||||||||||||||
| Comment by Kevin Albertson [ 13/Oct/23 ] | |||||||||||||||||
"Canonical Extended" refers to the JSON representation. In BSON, decimal128 is a separate type from double. Extending the example above, a decimal128 can be iterated as follows:
| |||||||||||||||||
| Comment by arun mr [ 13/Oct/23 ] | |||||||||||||||||
|
IN my scenario the output from bson_init_from_json is used to create bson iterator and the iterator is used to fetch the data, like below. const char from_json = "{\"a\" : {\"$numberDecimal\" : \"0.1234567890123456789012345\"}}"; bson_t b; bson_error_t error; bool ok = bson_init_from_json (&b, from_json, strlen (from_json), &error); if (!ok) { printf ("error parsing: %s\n", error.message); }bson_iter_t bsonIter; bson_iter_init(&bsonIter, &b) is there any " canonical_extended" version of bson_iter_init ?? | |||||||||||||||||
| Comment by Kevin Albertson [ 12/Oct/23 ] | |||||||||||||||||
|
I expect the precision of 0.1234567890123456789012345 cannot be represented exactly in a double. libbson parses JSON double values with strtod and prints with the format %.20g. Use of PyMongo shows similar precision:
The Decimal128 type can be represented in Extended JSON. Example with libbson:
| |||||||||||||||||
| Comment by PM Bot [ 15/Sep/23 ] | |||||||||||||||||
|
Hi arunmrmv@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |