Open wolfgangwalther opened 2 years ago
Hi!
There could be multiple ways to approach this issue. The simplest one would be to utilize the arbitrary_precision
feature of serde-json
- in this case, any number will be parsed as a string. Roughly:
rust_decimal::Decimal
) instead of using as_<type>
convertorsrust_decimal::Decimal
many things will work out of the box, as it implements comparison (though, it might require some adaptation)And it will hit performance for the common case (unless behind a feature flag) because it will use String
in many cases where smaller types would work. Though, it is kind of a thing that needs to be implemented anyway to support working with large numbers without precision loss on the Rust side.
Answering your question
Is this something that needs to be supported in pyo3 first?
There is no requirement for this to be implemented on the pyo3
side. Though, we'll need to convert values manually :)
It might be also good to take a look at this issue first. Implementing it will allow us to use a specialized implementation for Python objects and maybe avoid unnecessary string conversions & using that abovementioned feature flag at all.
I'm using
jsonschema-rs
inside PostgreSQL viaplpython3u
. When I use PG'sTRANSFORM FOR TYPE JSONB
instead of python'sjson.loads(...)
floats are converted todecimal.Decimal
.This results in:
The error is thrown here: https://github.com/Stranger6667/jsonschema-rs/blob/0515c955a484d0a33308c2ed8c0057c7f6fb84a1/bindings/python/src/ser.rs#L223-L226
Is it possible to support
Decimal
, too?Float is serialized like this: https://github.com/Stranger6667/jsonschema-rs/blob/0515c955a484d0a33308c2ed8c0057c7f6fb84a1/bindings/python/src/ser.rs#L124-L126
Is this something that needs to be supported in
pyo3
first?