From 3aab0013529e68215e56284069a9a6bd98f1e7db Mon Sep 17 00:00:00 2001 From: liukun4515 Date: Fri, 12 Aug 2022 11:41:02 +0800 Subject: [PATCH] address comment --- arrow/src/array/array_decimal.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/arrow/src/array/array_decimal.rs b/arrow/src/array/array_decimal.rs index 570c7f902d23..455383124c03 100644 --- a/arrow/src/array/array_decimal.rs +++ b/arrow/src/array/array_decimal.rs @@ -332,28 +332,20 @@ impl Decimal256Array { // Validates decimal values in this array can be properly interpreted // with the specified precision. fn validate_decimal_precision(&self, precision: usize) -> Result<()> { - let current_end = self.data.len(); - let mut current: usize = 0; - let data = &self.data; - - while current != current_end { - if self.is_null(current) { - current += 1; - continue; - } else { - let offset = current + data.offset(); - current += 1; + (0..self.len()).try_for_each(|idx| { + if self.is_valid(idx) { let raw_val = unsafe { - let pos = self.value_offset_at(offset); + let pos = self.value_offset(idx); std::slice::from_raw_parts( self.raw_value_data_ptr().offset(pos as isize), Self::VALUE_LENGTH as usize, ) }; - validate_decimal256_precision_with_lt_bytes(raw_val, precision)?; + validate_decimal256_precision_with_lt_bytes(raw_val, precision) + } else { + Ok(()) } - } - Ok(()) + }) } /// Returns a Decimal array with the same data as self, with the