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]); +}