Jefffrey commented on code in PR #20205:
URL: https://github.com/apache/datafusion/pull/20205#discussion_r2793930675


##########
datafusion/functions/src/math/nanvl.rs:
##########
@@ -110,42 +125,54 @@ impl ScalarUDFImpl for NanvlFunc {
 }
 
 /// Nanvl SQL function
+///
+/// Only propagates nulls from x:

Review Comment:
   This is misleading as we can still propagate nulls from y too (as 
highlighted by the 2nd point)



##########
datafusion/functions/src/math/nanvl.rs:
##########
@@ -110,42 +125,54 @@ impl ScalarUDFImpl for NanvlFunc {
 }
 
 /// Nanvl SQL function
+///
+/// Only propagates nulls from x:
+/// - x is NULL -> output is NULL
+/// - x is NaN -> output is y (even if y is NULL)
+/// - x is not NaN -> output is x (regardless of y)
 fn nanvl(args: &[ArrayRef]) -> Result<ArrayRef> {
     match args[0].data_type() {
         Float64 => {
-            let compute_nanvl = |x: f64, y: f64| {
-                if x.is_nan() { y } else { x }
-            };
-
-            let x = args[0].as_primitive() as &Float64Array;
-            let y = args[1].as_primitive() as &Float64Array;
-            arrow::compute::binary::<_, _, _, Float64Type>(x, y, compute_nanvl)
-                .map(|res| Arc::new(res) as _)
-                .map_err(DataFusionError::from)
+            let x = args[0].as_primitive::<Float64Type>();
+            let y = args[1].as_primitive::<Float64Type>();
+            let result: Float64Array = x
+                .iter()
+                .zip(y.iter())
+                .map(|(xv, yv)| match xv {
+                    None => None,                  // x is null -> null
+                    Some(xv) if xv.is_nan() => yv, // x is NaN -> y
+                    some_xv => some_xv,            // x is valid -> x
+                })

Review Comment:
   ```rust
                   .map(|(x_value, y_value)| match x_value {
                       Some(x_value) if x_value.is_nan() => y_value,
                       _ => x_value,
   ```
   
   Can keep this simple



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