From 96d64d35a8508888eecbe87c8f07714e286ab99d Mon Sep 17 00:00:00 2001 From: comphead Date: Fri, 25 Jul 2025 12:58:27 -0700 Subject: [PATCH] fix: TrivialValueAccumulators to ignore nulls for `ignore nulls` --- datafusion/functions-aggregate/src/first_last.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/datafusion/functions-aggregate/src/first_last.rs b/datafusion/functions-aggregate/src/first_last.rs index 0856237d08cb5..83307469e895b 100644 --- a/datafusion/functions-aggregate/src/first_last.rs +++ b/datafusion/functions-aggregate/src/first_last.rs @@ -833,8 +833,11 @@ impl Accumulator for TrivialFirstValueAccumulator { filter_states_according_to_is_set(&states[0..1], flags)?; if let Some(first) = filtered_states.first() { if !first.is_empty() { - self.first = ScalarValue::try_from_array(first, 0)?; - self.is_set = true; + let first = ScalarValue::try_from_array(first, 0)?; + if !self.ignore_nulls || !first.is_null() { + self.first = first; + self.is_set = true; + } } } } @@ -1326,8 +1329,11 @@ impl Accumulator for TrivialLastValueAccumulator { let filtered_states = filter_states_according_to_is_set(&states[0..1], flags)?; if let Some(last) = filtered_states.last() { if !last.is_empty() { - self.last = ScalarValue::try_from_array(last, 0)?; - self.is_set = true; + let last = ScalarValue::try_from_array(last, 0)?; + if !self.ignore_nulls || !last.is_null() { + self.last = last; + self.is_set = true; + } } } Ok(())