From a6e0bac94d57273d43419aad670fe51d53c9c4a8 Mon Sep 17 00:00:00 2001 From: bss-k <319963876+bss-k@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:19:26 -0800 Subject: [PATCH] fix: return NULL from array_length below an empty nested list --- datafusion/functions-nested/src/length.rs | 3 +++ datafusion/sqllogictest/test_files/array/array_length.slt | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/datafusion/functions-nested/src/length.rs b/datafusion/functions-nested/src/length.rs index dbdbb4cedeaec..397a18edb4fa8 100644 --- a/datafusion/functions-nested/src/length.rs +++ b/datafusion/functions-nested/src/length.rs @@ -204,6 +204,9 @@ fn compute_array_length( if current_dimension == dimension { return Ok(Some(value.len() as u64)); } + if value.is_empty() { + return Ok(None); + } match value.data_type() { List(..) => { diff --git a/datafusion/sqllogictest/test_files/array/array_length.slt b/datafusion/sqllogictest/test_files/array/array_length.slt index a4cf882efa82f..41c9eed02a77e 100644 --- a/datafusion/sqllogictest/test_files/array/array_length.slt +++ b/datafusion/sqllogictest/test_files/array/array_length.slt @@ -58,6 +58,12 @@ select array_length(make_array()), array_length(make_array(), 1), array_length(m ---- 0 0 NULL +# array_length of a dimension below an empty nested list is NULL +query IIII +select array_length(arrow_cast(make_array(), 'List(List(Int64))'), 1), array_length(arrow_cast(make_array(), 'List(List(Int64))'), 2), array_length(arrow_cast(make_array(), 'LargeList(List(Int64))'), 2), array_length(arrow_cast(make_array(make_array()), 'List(List(List(Int64)))'), 3); +---- +0 NULL NULL NULL + # array_length scalar function #6 nested array query III select array_length([[1, 2, 3, 4], [5, 6, 7, 8]]), array_length([[1, 2, 3, 4], [5, 6, 7, 8]], 1), array_length([[1, 2, 3, 4], [5, 6, 7, 8]], 2);