Dandandan commented on code in PR #23458:
URL: https://github.com/apache/datafusion/pull/23458#discussion_r3563460572
##########
datafusion/functions/src/math/nanvl.rs:
##########
@@ -148,46 +152,81 @@ fn scalar_is_nan(scalar: &ScalarValue) -> bool {
/// - otherwise -> output is x (which may itself be NULL)
fn nanvl(args: &[ArrayRef]) -> Result<ArrayRef> {
match args[0].data_type() {
- Float64 => {
- let x = args[0].as_primitive::<Float64Type>();
- let y = args[1].as_primitive::<Float64Type>();
- let result: Float64Array = x
- .iter()
- .zip(y.iter())
- .map(|(x_value, y_value)| match x_value {
- Some(x_value) if x_value.is_nan() => y_value,
- _ => x_value,
- })
- .collect();
- Ok(Arc::new(result) as ArrayRef)
- }
- Float32 => {
- let x = args[0].as_primitive::<Float32Type>();
- let y = args[1].as_primitive::<Float32Type>();
- let result: Float32Array = x
+ Float64 => Ok(Arc::new(nanvl_impl::<Float64Type>(
+ args[0].as_primitive(),
+ args[1].as_primitive(),
+ ))),
+ Float32 => Ok(Arc::new(nanvl_impl::<Float32Type>(
+ args[0].as_primitive(),
+ args[1].as_primitive(),
+ ))),
+ Float16 => Ok(Arc::new(nanvl_impl::<Float16Type>(
+ args[0].as_primitive(),
+ args[1].as_primitive(),
+ ))),
+ other => exec_err!("Unsupported data type {other:?} for function
nanvl"),
+ }
+}
+
+/// Element-wise `nanvl`: selects `y[i]` where `x[i]` is `NaN`, otherwise
`x[i]`
+/// (a null `x` selects `x`, i.e. propagates null).
+///
+/// This produces output identical to collecting an iterator of `Option`s but
+/// splits out a null-free fast path that iterates the raw value slices,
+/// skipping per-element validity checks and `Option` handling. The null-aware
+/// path builds its null buffer lazily via [`NullBufferBuilder`] exactly as the
+/// `FromIterator` implementation does, so the result is byte-for-byte the
same.
Review Comment:
```suggestion
/// path builds its null buffer lazily via [`NullBufferBuilder`].
```
--
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]