Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions arrow-cast/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,14 @@ pub fn parse_decimal<T: DecimalType>(
}

if !is_e_notation {
if scale == 0 && fractionals > 0 {
// The input string contained some fractional digits after the decimal point despite
// the scale being zero. Eject all the fractional digits from the number.
result = result.div_wrapping(base.pow_wrapping(fractionals as _));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be correct if there are many fractional digits, e.g. 20+ ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would, added another test case on that note (("123.000000000000000000004", 123)).

digits -= fractionals as u8;
fractionals = 0;
}

if fractionals < scale {
let exp = scale - fractionals;
if exp as u8 + digits > precision {
Expand Down Expand Up @@ -2636,6 +2644,7 @@ mod tests {
("12345678908765.123456", 3),
("123456789087651234.56e-4", 3),
("1234560000000", 0),
("12345678900.0", 0),
("1.23456e12", 0),
];
for (s, scale) in overflow_parse_tests {
Expand Down Expand Up @@ -2752,6 +2761,25 @@ mod tests {
let result = parse_decimal::<Decimal256Type>(s, 76, scale);
assert_eq!(i, result.unwrap());
}

let zero_scale_tests = [
("0.123", 0),
("1.0", 1),
("1.2", 1),
("1.00", 1),
("1.23", 1),
("1.000", 1),
("1.123", 1),
("123.0", 123),
("123.4", 123),
("123.00", 123),
("123.45", 123),
("123.000000000000000000004", 123),
];
for (s, i) in zero_scale_tests {
let result_128 = parse_decimal::<Decimal128Type>(s, 3, 0).unwrap();
assert_eq!(i, result_128);
}
}

#[test]
Expand Down
Loading