alamb commented on a change in pull request #9682:
URL: https://github.com/apache/arrow/pull/9682#discussion_r607265467
##########
File path: rust/arrow/src/compute/kernels/cast.rs
##########
@@ -937,114 +1048,169 @@ 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 string = from.value(i);
+ let result = lexical_core::parse(string.as_bytes());
+ if cast_options.safe {
+ Ok(result.ok())
+ } else {
+ Some(result.map_err(|_| {
+ ArrowError::CastError(format!(
+ "Cannot cast string '{}' to value of {} type",
+ string,
+ std::any::type_name::<T>()
+ ))
+ }))
+ .transpose()
+ }
+ }
+ })
+ .collect::<Result<Vec<Option<_>>>>()?;
Review comment:
FYI I tried here: https://github.com/seddonm1/arrow/pull/2 and it seems
to work well. I am trying to gather some performance benchmarks to see if it
matters
--
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:
[email protected]