sandugood commented on code in PR #22134:
URL: https://github.com/apache/datafusion/pull/22134#discussion_r3656557488


##########
datafusion/functions-window/src/lead_lag.rs:
##########
@@ -501,6 +518,89 @@ fn shift_with_default_value(
     }
 }
 
+fn shift_with_array_default(
+    array: &ArrayRef,
+    offset: i64,
+    default_values: &ArrayRef,
+) -> Result<ArrayRef> {
+    use datafusion_common::arrow::compute::concat;
+
+    let value_len = array.len() as i64;
+    if offset == 0 {
+        return Ok(Arc::clone(array));
+    }
+    if offset == i64::MIN || offset.abs() >= value_len {
+        return Ok(Arc::clone(default_values));
+    }
+
+    let slice_offset = (-offset).clamp(0, value_len) as usize;
+    let length = array.len() - offset.unsigned_abs() as usize;
+    let slice = array.slice(slice_offset, length);
+
+    let defaults_slice = if offset > 0 {
+        // Lag: defaults go at the beginning
+        default_values.slice(0, offset.unsigned_abs() as usize)
+    } else {
+        // Lead: defaults go at the end
+        let start = default_values.len() - offset.unsigned_abs() as usize;
+        default_values.slice(start, offset.unsigned_abs() as usize)
+    };
+
+    if offset > 0 {
+        concat(&[defaults_slice.as_ref(), slice.as_ref()])
+    } else {
+        concat(&[slice.as_ref(), defaults_slice.as_ref()])
+    }
+    .map_err(|e| arrow_datafusion_err!(e))
+}
+
+fn evaluate_all_with_ignore_null_and_array_default(
+    array: &ArrayRef,
+    offset: i64,
+    default_values: &ArrayRef,
+    is_lag: bool,
+) -> Result<ArrayRef> {
+    let valid_indices: Vec<usize> = 
array.nulls().unwrap().valid_indices().collect();

Review Comment:
   Good catch, thank you!
   Added a docstring as well as the link to the arrow docs



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