viirya commented on code in PR #7716:
URL: https://github.com/apache/datafusion-comet/pull/7716#discussion_r4764318560
##########
native/spark-expr/src/conversion_funcs/string.rs:
##########
@@ -1002,22 +917,37 @@ fn parse_decimal_str(
}
}
- let integral_value = digits_to_i128(integral_part)
- .ok_or_else(|| invalid_decimal_cast(original_str, precision, scale))?;
-
- let fractional_value = digits_to_i128(fractional_part)
- .ok_or_else(|| invalid_decimal_cast(original_str, precision, scale))?;
-
- // Combine: value = integral * 10^fractional_scale + fractional.
- // A fractional_scale beyond 38 cannot fit in an i128, so pow10_i128
returns None and this
- // maps to the invalid-decimal error path instead of panicking.
- let mantissa = pow10_i128(fractional_scale as u32)
- .and_then(|p| integral_value.checked_mul(p))
- .and_then(|v| v.checked_add(fractional_value))
- .ok_or_else(|| invalid_decimal_cast(original_str, precision, scale))?;
+ let adjustment = i64::from(scale) - i64::from(final_scale);
+ let digits = || significant_digits(integral_part, fractional_part) as i64;
+ if adjustment > 38 {
+ return Ok((digits() == 0).then_some(0));
+ }
+ if -adjustment > max_power_of_ten(options.decimal_full_divisor_range) {
+ let digits = digits();
+ // SPARK-60119 avoids the divisor for values below 0.01 ulp or above
+ // the target precision. Otherwise setScale needs it for a nonzero
value.
+ let needs_divisor = !options.decimal_tiny_to_zero
Review Comment:
Makes sense. Keeping the exact Spark window costs one line, so I'm fine
leaving it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]