-
Notifications
You must be signed in to change notification settings - Fork 1
fix: serialize decimals as quoted strings in JSON output #2
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
base: release-53.4.0
Are you sure you want to change the base?
fix: serialize decimals as quoted strings in JSON output #2
Conversation
arrow-json/src/writer/encoder.rs
Outdated
let options = FormatOptions::new().with_display_error(true); | ||
let formatter = ArrayFormatter::try_new(array, &options)?; | ||
(Box::new(RawArrayFormatter(formatter)) as _, array.nulls().cloned()) | ||
(Box::new(formatter) as _, array.nulls().cloned()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about to extend FormatOptions
instead? This allows users to choose the format and keeps backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, could you take a look?
Thank you for the patch! We need to fix tests here: Btw, does decimal deserializer properly works with input strings? |
I use |
Ok, it seems that deserializer also uses it https://github.com/tarantool/arrow-rs/blob/main/arrow-json/src/reader/decimal_array.rs#L57-L60, so it will be able to deserialize strings as decimals. |
arrow-cast/src/display.rs
Outdated
duration_format: DurationFormat, | ||
/// If set to `true`, decimal values will be formatted as strings instead of numbers | ||
/// This is useful for JSON output to preserve precision | ||
decimal_as_string: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to change it to enum of formats instead as it's done for others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I refactored it to use an enum.
Co-authored-by: Artem Novikov <33791946+novartole@users.noreply.github.com>
For correct serialization of decimal types into JSON we want them to be serialized as strings instead of numbers so they don't loose precision.