coderfender commented on code in PR #2472:
URL: https://github.com/apache/datafusion-comet/pull/2472#discussion_r2415278558
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1464,6 +1465,104 @@ where
cast_float_to_string!(from, _eval_mode, f32, Float32Array, OffsetSize)
}
+fn cast_int_to_decimal128_internal<T>(
+ array: &PrimitiveArray<T>,
+ precision: u8,
+ scale: i8,
+ eval_mode: EvalMode,
+) -> SparkResult<ArrayRef>
+where
+ T: ArrowPrimitiveType,
+ T::Native: Into<i128>,
+{
+ let mut builder = Decimal128Builder::with_capacity(array.len());
+ let multiplier = 10_i128.pow(scale as u32);
+
+ for i in 0..array.len() {
+ if array.is_null(i) {
+ builder.append_null();
+ } else {
+ let v = array.value(i).into();
+ let scaled = v.checked_mul(multiplier);
+ match scaled {
+ Some(scaled) => {
+ if !is_validate_decimal_precision(scaled, precision) {
+ match eval_mode {
+ EvalMode::Ansi => {
+ return Err(SparkError::NumericValueOutOfRange {
+ value: v.to_string(),
+ precision,
+ scale,
+ });
+ }
+ EvalMode::Try | EvalMode::Legacy =>
builder.append_null(),
+ }
+ } else {
+ builder.append_value(scaled);
+ }
+ }
+ _ => {
+ return Err(SparkError::NumericValueOutOfRange {
+ value: v.to_string(),
+ precision,
+ scale,
+ })
+ }
Review Comment:
Done. Thank you for the suggestion @andygrove
--
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]