seddonm1 commented on a change in pull request #9682: URL: https://github.com/apache/arrow/pull/9682#discussion_r593418530
########## File path: rust/arrow/src/compute/kernels/cast.rs ########## @@ -939,133 +1244,184 @@ where from.as_any() .downcast_ref::<GenericStringArray<Offset>>() .unwrap(), - ))) + cast_options, + )?)) } fn string_to_numeric_cast<T, Offset: StringOffsetSizeTrait>( from: &GenericStringArray<Offset>, -) -> PrimitiveArray<T> + cast_options: &CastOptions, +) -> Result<PrimitiveArray<T>> where T: ArrowNumericType, <T as ArrowPrimitiveType>::Native: lexical_core::FromLexical, { - let iter = (0..from.len()).map(|i| { - if from.is_null(i) { - None - } else { - lexical_core::parse(from.value(i).as_bytes()).ok() - } - }); + let vec = (0..from.len()) + .map(|i| { + if from.is_null(i) { + Ok(None) + } else { + let result = lexical_core::parse(from.value(i).as_bytes()); + if cast_options.safe { + Ok(result.ok()) + } else { + Some(result.map_err(|_| { + ArrowError::CastError( Review comment: Agree but i guess we just need to verify that these are not logged as it is easy to leak data. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org