-
Notifications
You must be signed in to change notification settings - Fork 135
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
RUST-1592 Support decimal128 to/from human-readable strings #404
Conversation
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.
looks good! just a few questions/comments for my own understanding.
src/extjson/models.rs
Outdated
impl Decimal128 { | ||
pub(crate) fn parse(self) -> extjson::de::Result<crate::Decimal128> { | ||
self.value.parse().map_err(|err| { | ||
dbg!(err); |
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.
is this left over from debugging?
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.
Whoops, yes, fixed.
src/decimal128.rs
Outdated
const BIAS: i16 = 6176; | ||
const TINY: i16 = -6176; | ||
const MAX: i16 = 6111; | ||
|
||
const UNUSED_BITS: usize = 2; | ||
const PACKED_WIDTH: usize = 14; |
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.
can we add comments on these consts (and same below) indicating what they represent?
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 thought, done.
decimal_str = if rest.is_empty() { "0" } else { rest }; | ||
|
||
// Check decimal precision | ||
{ |
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's the purpose of this separated scope?
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.
Just making sure that len
doesn't accidentally leak into other things.
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.
lgtm!
RUST-1592
This adds support for the standard human-readable string traits (
Display
andFromStr
) toDecimal128
via an intermediateParsedDecimal128
struct, as well as using such in the extjson format. While it's possible to generate/parse the strings directly from the packed binary representation, I opted for the intermediate struct because it's way more readable and it'll be useful if we ever want to support more operations.