Skip to content

Commit 79bc1bf

Browse files
committed
Fix array_element of empty array
1 parent b718aa6 commit 79bc1bf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

datafusion/functions-nested/src/extract.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ where
224224
i64: TryInto<O>,
225225
{
226226
let values = array.values();
227+
if values.data_type().is_null() {
228+
return Ok(Arc::new(NullArray::new(array.len())));
229+
}
230+
227231
let original_data = values.to_data();
228232
let capacity = Capacities::Array(original_data.len());
229233

datafusion/sqllogictest/test_files/array.slt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,12 @@ NULL 23
14351435
NULL 43
14361436
5 NULL
14371437

1438+
# array_element of empty array
1439+
query T
1440+
select coalesce(array_element([], 1), array_element(NULL, 1), 'ok');
1441+
----
1442+
ok
1443+
14381444

14391445
## array_max
14401446
# array_max scalar function #1 (with positive index)

0 commit comments

Comments
 (0)