From 98568e74da369141936dd8233dfe74fb135209d4 Mon Sep 17 00:00:00 2001 From: QuenKar <47681251+QuenKar@users.noreply.github.com> Date: Thu, 16 Nov 2023 19:08:22 +0800 Subject: [PATCH] fix: iter_data() doesn't stop --- src/datatypes/src/vectors/decimal.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/datatypes/src/vectors/decimal.rs b/src/datatypes/src/vectors/decimal.rs index bb3402470bd1..5ca220611e67 100644 --- a/src/datatypes/src/vectors/decimal.rs +++ b/src/datatypes/src/vectors/decimal.rs @@ -252,11 +252,9 @@ impl<'a> Iterator for Decimal128Iter<'a> { type Item = Option; fn next(&mut self) -> Option { - Some( - self.iter - .next() - .and_then(|v| v.map(|v| Decimal128::new(v, self.precision, self.scale))), - ) + self.iter + .next() + .map(|item| item.map(|v| Decimal128::new(v, self.precision, self.scale))) } fn size_hint(&self) -> (usize, Option) { @@ -519,3 +517,21 @@ pub mod tests { assert!(array.is_null(4)); } } +#[test] +fn test_decimal28_vector_iter_data() { + let vector = Decimal128Vector::from_values(vec![1, 2, 3, 4]) + .with_precision_and_scale(3, 1) + .unwrap(); + let mut iter = vector.iter_data(); + assert_eq!(iter.next(), Some(Some(Decimal128::new(1, 3, 1)))); + assert_eq!(iter.next(), Some(Some(Decimal128::new(2, 3, 1)))); + assert_eq!(iter.next(), Some(Some(Decimal128::new(3, 3, 1)))); + assert_eq!(iter.next(), Some(Some(Decimal128::new(4, 3, 1)))); + assert_eq!(iter.next(), None); + + let values = vector + .iter_data() + .filter_map(|v| v.map(|x| x.val() * 2)) + .collect::>(); + assert_eq!(values, vec![2, 4, 6, 8]); +}