Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions datafusion/functions-window/src/lead_lag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,12 @@ fn evaluate_all_with_ignore_null(
default_value: &ScalarValue,
is_lag: bool,
) -> Result<ArrayRef, DataFusionError> {
let valid_indices: Vec<usize> =
array.nulls().unwrap().valid_indices().collect::<Vec<_>>();
// Arrays without NULLs do not necessarily have a null bitmap.
let Some(nulls) = array.nulls() else {
return shift_with_default_value(array, offset, default_value);
};

let valid_indices: Vec<usize> = nulls.valid_indices().collect::<Vec<_>>();
let direction = !is_lag;
let new_array_results: Result<Vec<_>, DataFusionError> = (0..array.len())
.map(|id| {
Expand Down Expand Up @@ -827,4 +831,25 @@ mod tests {
.collect::<Int32Array>(),
)
}

#[test]
fn test_ignore_nulls_without_null_bitmap() -> Result<()> {
let input = Int32Array::from(vec![1, 2, 3]);
assert!(input.nulls().is_none());
let input: ArrayRef = Arc::new(input);

for (offset, expected) in [
(1, Int32Array::from(vec![None, Some(1), Some(2)])),
(-1, Int32Array::from(vec![Some(2), Some(3), None])),
] {
let actual = evaluate_all_with_ignore_null(
&input,
offset,
&ScalarValue::Int32(None),
offset > 0,
)?;
assert_eq!(expected, *as_int32_array(&actual)?);
}
Ok(())
}
}
Loading