comphead commented on code in PR #5080:
URL: https://github.com/apache/datafusion-comet/pull/5080#discussion_r3675553373


##########
native/spark-expr/src/math_funcs/internal/make_decimal.rs:
##########
@@ -58,14 +60,83 @@ pub fn spark_make_decimal(
     }
 }
 
-/// Convert the input long to decimal with the given maximum precision. If 
overflows, returns null
-/// instead.
+/// Convert the input long to decimal with the given maximum precision. On 
overflow, errors when
+/// `fail_on_error` is set (Spark's `nullOnOverflow = false`, i.e. ANSI mode) 
and returns null
+/// otherwise.
 #[inline]
-fn long_to_decimal(v: &Option<i64>, precision: u8, scale: i8) -> Option<i128> {
+fn long_to_decimal(
+    v: &Option<i64>,
+    precision: u8,
+    scale: i8,
+    fail_on_error: bool,
+) -> DataFusionResult<Option<i128>> {
     match v {

Review Comment:
   the block can be rewritten more concise
   
   ```
   v.map_or(Ok(None), |v| {
       let v = v as i128;
       match validate_decimal_precision(v, precision, scale) {
           Ok(()) => Ok(Some(v)),
           Err(_) if fail_on_error => Err(DataFusionError::External(Box::new(
               decimal_overflow_error(v, precision, scale),
           ))),
           Err(_) => Ok(None),
       }
   })
   ```



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