Skip to content

Commit

Permalink
Use bigdecimal env
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgao committed Nov 28, 2024
1 parent f6c92fe commit 92345ea
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[env]
RUST_BIGDECIMAL_FMT_EXPONENTIAL_LOWER_THRESHOLD="100"
RUST_BIGDECIMAL_FMT_EXPONENTIAL_UPPER_THRESHOLD="100"
25 changes: 1 addition & 24 deletions datafusion/sqllogictest/src/engines/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,7 @@ pub(crate) fn big_decimal_to_str(value: BigDecimal) -> String {
// Round the value to limit the number of decimal places
let value = value.round(12).normalized();
// Format the value to a string
format_big_decimal(value)
}

fn format_big_decimal(value: BigDecimal) -> String {
let (integer, scale) = value.into_bigint_and_exponent();
let mut str = integer.to_str_radix(10);
if scale <= 0 {
// Append zeros to the right of the integer part
str.extend(std::iter::repeat('0').take(scale.unsigned_abs() as usize));
str
} else {
let (sign, unsigned_len, unsigned_str) = if integer.is_negative() {
("-", str.len() - 1, &str[1..])
} else {
("", str.len(), &str[..])
};
let scale = scale as usize;
if unsigned_len <= scale {
format!("{}0.{:0>scale$}", sign, unsigned_str)
} else {
str.insert(str.len() - scale, '.');
str
}
}
value.to_string()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ SELECT var_pop(c2) FROM aggregate_test_100
query R
SELECT var_pop(c6) FROM aggregate_test_100
----
26156334342021890000000000000000000000
2615633434202189e+22

# csv_query_variance_3
query R
Expand Down

0 comments on commit 92345ea

Please sign in to comment.