alamb commented on code in PR #5891:
URL: https://github.com/apache/arrow-datafusion/pull/5891#discussion_r1160265269


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -170,43 +184,86 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
         )));
     }
 
-    let mut decimal_places =
-        &(Arc::new(Int64Array::from_value(0, args[0].len())) as ArrayRef);
+    let mut decimal_places = 
ColumnarValue::Scalar(ScalarValue::Int64(Some(0)));
 
     if args.len() == 2 {
-        decimal_places = &args[1];
+        decimal_places = ColumnarValue::Array(args[1].clone());
     }
 
     match args[0].data_type() {
-        DataType::Float64 => 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())
-                }
+        DataType::Float64 => match decimal_places {
+            ColumnarValue::Scalar(ScalarValue::Int64(Some(decimal_places))) => 
{
+                let decimal_places = decimal_places.try_into().unwrap();
+
+                Ok(Arc::new(make_function_scalar_inputs!(
+                    &args[0],
+                    "value",
+                    Float64Array,
+                    {
+                        |value: f64| {
+                            (value * 10.0_f64.powi(decimal_places)).round()
+                                / 10.0_f64.powi(decimal_places)
+                        }
+                    }
+                )) as ArrayRef)
             }
-        )) as ArrayRef),
-
-        DataType::Float32 => Ok(Arc::new(make_function_inputs2!(
-            &args[0],
-            decimal_places,
-            "value",
-            "decimal_places",
-            Float32Array,
-            Int64Array,
-            {
-                |value: f32, decimal_places: i64| {
-                    (value * 
10.0_f32.powi(decimal_places.try_into().unwrap())).round()
-                        / 10.0_f32.powi(decimal_places.try_into().unwrap())
+            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())
+                    }
                 }
+            )) as ArrayRef),
+            _ => Err(DataFusionError::Internal(
+                "round function requires a scalar or array for decimal_places"
+                    .to_string(),
+            )),
+        },
+
+        DataType::Float32 => match decimal_places {
+            ColumnarValue::Scalar(ScalarValue::Int64(Some(decimal_places))) => 
{
+                let decimal_places = decimal_places.try_into().unwrap();
+
+                Ok(Arc::new(make_function_scalar_inputs!(
+                    &args[0],
+                    "value",
+                    Float32Array,
+                    {
+                        |value: f32| {
+                            (value * 10.0_f32.powi(decimal_places)).round()

Review Comment:
   👍 



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

Reply via email to