alamb commented on code in PR #10899:
URL: https://github.com/apache/datafusion/pull/10899#discussion_r1638480860


##########
datafusion/functions/src/math/round.rs:
##########
@@ -128,29 +134,41 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
                     }
                 )) as ArrayRef)
             }
-            ColumnarValue::Array(decimal_places) => 
Ok(Arc::new(make_function_inputs2!(
-                &args[0],
-                decimal_places,
-                "value",
-                "decimal_places",
-                Float64Array,
-                Int64Array,
-                {
-                    |value: f64, decimal_places: i64| {
-                        (value * 
10.0_f64.powi(decimal_places.try_into().unwrap()))
-                            .round()
-                            / 10.0_f64.powi(decimal_places.try_into().unwrap())
+            ColumnarValue::Array(_) => {
+                let ColumnarValue::Array(decimal_places) =
+                    decimal_places.cast_to(&Int32, None).map_err(|e| {
+                        exec_datafusion_err!("Invalid values for decimal 
places: {e}")
+                    })?
+                else {
+                    panic!("Unexpected result of ColumnarValue::Array.cast")

Review Comment:
   I think you can avoid the panic by collaspsing the two 
`ColumnarValue::Array` 
   
   So instead of
   
   ```rust
               ColumnarValue::Array(_) => {
      let ColumnarValue::Array(decimal_places) =
                       decimal_places.cast_to(&Int32, None).map_err(|e| {
                           exec_datafusion_err!("Invalid values for decimal 
places: {e}")
                       })?
                   else {
   ..
   ```
   
   ```rust
     ColumnarValue::Array(decimal_places) => { 
   ...
   ```



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