Skip to content

Commit c60bc81

Browse files
committed
Update to bigdecimal 0.4.7
Utilize new `to_plain_string` function
1 parent 2d59a06 commit c60bc81

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ arrow-ipc = { version = "53.3.0", default-features = false, features = [
9393
arrow-ord = { version = "53.3.0", default-features = false }
9494
arrow-schema = { version = "53.3.0", default-features = false }
9595
async-trait = "0.1.73"
96-
bigdecimal = "0.4.6"
96+
bigdecimal = "0.4.7"
9797
bytes = "1.4"
9898
chrono = { version = "0.4.38", default-features = false }
9999
ctor = "0.2.0"

datafusion/sqllogictest/src/engines/conversion.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,30 +106,7 @@ pub(crate) fn big_decimal_to_str(value: BigDecimal) -> String {
106106
// Round the value to limit the number of decimal places
107107
let value = value.round(12).normalized();
108108
// Format the value to a string
109-
format_big_decimal(value)
110-
}
111-
112-
fn format_big_decimal(value: BigDecimal) -> String {
113-
let (integer, scale) = value.into_bigint_and_exponent();
114-
let mut str = integer.to_str_radix(10);
115-
if scale <= 0 {
116-
// Append zeros to the right of the integer part
117-
str.extend(std::iter::repeat('0').take(scale.unsigned_abs() as usize));
118-
str
119-
} else {
120-
let (sign, unsigned_len, unsigned_str) = if integer.is_negative() {
121-
("-", str.len() - 1, &str[1..])
122-
} else {
123-
("", str.len(), &str[..])
124-
};
125-
let scale = scale as usize;
126-
if unsigned_len <= scale {
127-
format!("{}0.{:0>scale$}", sign, unsigned_str)
128-
} else {
129-
str.insert(str.len() - scale, '.');
130-
str
131-
}
132-
}
109+
value.to_plain_string()
133110
}
134111

135112
#[cfg(test)]
@@ -158,6 +135,8 @@ mod tests {
158135
assert_decimal_str_eq!(11, 0, "11");
159136
assert_decimal_str_eq!(11, -1, "110");
160137
assert_decimal_str_eq!(0, 0, "0");
138+
assert_decimal_str_eq!(12345678901234567890123456789012345678_i128, 0, "12345678901234567890123456789012345678");
139+
assert_decimal_str_eq!(12345678901234567890123456789012345678_i128, 38, "0.123456789012");
161140

162141
// Negative cases
163142
assert_decimal_str_eq!(-110, 3, "-0.11");
@@ -166,6 +145,8 @@ mod tests {
166145
assert_decimal_str_eq!(-11, 1, "-1.1");
167146
assert_decimal_str_eq!(-11, 0, "-11");
168147
assert_decimal_str_eq!(-11, -1, "-110");
148+
assert_decimal_str_eq!(-12345678901234567890123456789012345678_i128, 0, "-12345678901234567890123456789012345678");
149+
assert_decimal_str_eq!(-12345678901234567890123456789012345678_i128, 38, "-0.123456789012");
169150

170151
// Round to 12 decimal places
171152
// 1.0000000000011 -> 1.000000000001

0 commit comments

Comments
 (0)