diff --git a/arrow-csv/src/reader/mod.rs b/arrow-csv/src/reader/mod.rs index c5fe20e9d915..29bdeb4e2895 100644 --- a/arrow-csv/src/reader/mod.rs +++ b/arrow-csv/src/reader/mod.rs @@ -866,21 +866,25 @@ fn parse_decimal_with_parameter( let mut negative = false; let mut result = T::Native::usize_as(0); - for byte in bytes[0..offset].iter().rev() { - match byte { - b'-' => { - negative = true; - } - b'0'..=b'9' => { - let add = - T::Native::usize_as((byte - b'0') as usize).mul_checked(base)?; - result = result.add_checked(add)?; - base = base.mul_checked(T::Native::usize_as(10))?; + bytes[0..offset] + .iter() + .rev() + .try_for_each::<_, Result<(), ArrowError>>(|&byte| { + match byte { + b'-' => { + negative = true; + } + b'0'..=b'9' => { + let add = T::Native::usize_as((byte - b'0') as usize) + .mul_checked(base)?; + result = result.add_checked(add)?; + base = base.mul_checked(T::Native::usize_as(10))?; + } + // because of the PARSE_DECIMAL_RE, bytes just contains digit、'-' and '.'. + _ => (), } - // because of the PARSE_DECIMAL_RE, bytes just contains digit、'-' and '.'. - _ => {} - } - } + Ok(()) + })?; if negative { result = result.neg_checked()?;