coderfender commented on code in PR #7528:
URL: https://github.com/apache/datafusion-comet/pull/7528#discussion_r4576676726


##########
native/spark-expr/src/conversion_funcs/numeric.rs:
##########
@@ -520,6 +520,16 @@ macro_rules! cast_float_to_int32_up {
     }};
 }
 
+/// 10^scale, or an error for a scale outside 0..=38. Negative scales need
+/// spark.sql.legacy.allowNegativeScaleOfDecimal, and the serde and Parquet 
scan both leave those
+/// to Spark.
+fn decimal_scale_factor(scale: i8, cast: &str) -> SparkResult<i128> {
+    u32::try_from(scale)
+        .ok()
+        .and_then(pow10_i128)
+        .ok_or_else(|| SparkError::Internal(format!("{cast}: unsupported 
decimal scale {scale}")))
+}

Review Comment:
   nit : given that this is seldom reached given the Scala guards, wonder if we 
could just print scale and not the cast expression itself ?



##########
native/spark-expr/src/conversion_funcs/numeric.rs:
##########
@@ -593,7 +603,7 @@ macro_rules! cast_decimal_to_int32_up {
             .downcast_ref::<Decimal128Array>()
             .expect("Expected a Decimal128ArrayType");
 
-        let divisor = 10_i128.pow($scale as u32);
+        let divisor = decimal_scale_factor($scale, 
"cast_decimal_to_integral")?;

Review Comment:
   nit : wonder if we can take `cast_decimal_to_integral` into string



-- 
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]

Reply via email to