Skip to content

Commit 9dee50f

Browse files
committed
fix: Supported null stride
1 parent 0eb39cc commit 9dee50f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

datafusion/functions-nested/src/extract.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ where
639639
if array.is_null(row_index)
640640
|| from_array.is_null(row_index)
641641
|| to_array.is_null(row_index)
642+
|| stride.map_or(false, |s| s.is_null(row_index))
642643
{
643644
mutable.extend_nulls(1);
644645
offsets.push(offsets[row_index] + O::usize_as(1));
@@ -726,6 +727,7 @@ where
726727
if array.is_null(row_index)
727728
|| from_array.is_null(row_index)
728729
|| to_array.is_null(row_index)
730+
|| stride.map_or(false, |s| s.is_null(row_index))
729731
{
730732
null_builder.append_null();
731733
offsets.push(current_offset);
@@ -1324,6 +1326,32 @@ mod tests {
13241326
vec![vec![Some(1), None], vec![Some(3), Some(4)], Vec::new(),]
13251327
);
13261328

1329+
// Test with NULL stride - should return NULL for rows with NULL stride
1330+
let stride_with_null = Int64Array::from(vec![Some(1), None, Some(1)]);
1331+
let result = general_list_view_array_slice::<i32>(
1332+
&array,
1333+
&from,
1334+
&to,
1335+
Some(&stride_with_null),
1336+
)?;
1337+
let result = result.as_ref().as_list_view::<i32>();
1338+
1339+
// First row: stride = 1, should return [1, None]
1340+
// Second row: stride = NULL, should return NULL
1341+
// Third row: stride = 1, empty array should return empty
1342+
assert!(!result.is_null(0)); // First row should not be null
1343+
assert!(result.is_null(1)); // Second row should be null (stride is NULL)
1344+
assert!(!result.is_null(2)); // Third row should not be null
1345+
1346+
let first_row: Vec<Option<i32>> = result
1347+
.value(0)
1348+
.as_any()
1349+
.downcast_ref::<Int32Array>()
1350+
.unwrap()
1351+
.iter()
1352+
.collect();
1353+
assert_eq!(first_row, vec![Some(1), None]);
1354+
13271355
Ok(())
13281356
}
13291357
}

datafusion/sqllogictest/test_files/array.slt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,19 @@ select array_slice(make_array(1, 2, 3, 4, 5), 5, 1, -2), array_slice(make_array(
19431943
----
19441944
[5, 3, 1] [o, l, h]
19451945

1946+
# Test NULL stride
1947+
query ??
1948+
select array_slice(make_array(1, 2, 3, 4, 5), 1, 5, NULL), array_slice(make_array('h', 'e', 'l', 'l', 'o'), 1, 5, NULL);
1949+
----
1950+
NULL NULL
1951+
1952+
# Test NULL stride
1953+
query ??
1954+
select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'), 1, 5, NULL),
1955+
array_slice(arrow_cast(make_array('h', 'e', 'l', 'l', 'o'), 'LargeList(Utf8)'), 1, 5, NULL);
1956+
----
1957+
NULL NULL
1958+
19461959
query ??
19471960
select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'), 2, 4), array_slice(arrow_cast(make_array('h', 'e', 'l', 'l', 'o'), 'LargeList(Utf8)'), 1, 2);
19481961
----

0 commit comments

Comments
 (0)