diff --git a/datafusion/physical-expr/src/aggregate/first_last.rs b/datafusion/physical-expr/src/aggregate/first_last.rs index 1602c316ea69..6ae7b4895ad6 100644 --- a/datafusion/physical-expr/src/aggregate/first_last.rs +++ b/datafusion/physical-expr/src/aggregate/first_last.rs @@ -165,8 +165,6 @@ struct FirstValueAccumulator { orderings: Vec, // Stores the applicable ordering requirement. ordering_req: LexOrdering, - // Whether merge_batch() is called before - is_merge_called: bool, } impl FirstValueAccumulator { @@ -185,7 +183,6 @@ impl FirstValueAccumulator { is_set: false, orderings, ordering_req, - is_merge_called: false, }) } @@ -201,9 +198,7 @@ impl Accumulator for FirstValueAccumulator { fn state(&self) -> Result> { let mut result = vec![self.first.clone()]; result.extend(self.orderings.iter().cloned()); - if !self.is_merge_called { - result.push(ScalarValue::Boolean(Some(self.is_set))); - } + result.push(ScalarValue::Boolean(Some(self.is_set))); Ok(result) } @@ -218,7 +213,6 @@ impl Accumulator for FirstValueAccumulator { } fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> { - self.is_merge_called = true; // FIRST_VALUE(first1, first2, first3, ...) // last index contains is_set flag. let is_set_idx = states.len() - 1; @@ -394,8 +388,6 @@ struct LastValueAccumulator { orderings: Vec, // Stores the applicable ordering requirement. ordering_req: LexOrdering, - // Whether merge_batch() is called before - is_merge_called: bool, } impl LastValueAccumulator { @@ -414,7 +406,6 @@ impl LastValueAccumulator { is_set: false, orderings, ordering_req, - is_merge_called: false, }) } @@ -430,9 +421,7 @@ impl Accumulator for LastValueAccumulator { fn state(&self) -> Result> { let mut result = vec![self.last.clone()]; result.extend(self.orderings.clone()); - if !self.is_merge_called { - result.push(ScalarValue::Boolean(Some(self.is_set))); - } + result.push(ScalarValue::Boolean(Some(self.is_set))); Ok(result) } @@ -446,7 +435,6 @@ impl Accumulator for LastValueAccumulator { } fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> { - self.is_merge_called = true; // LAST_VALUE(last1, last2, last3, ...) // last index contains is_set flag. let is_set_idx = states.len() - 1;