MCPcopy Create free account
hub / github.com/apache/arrow-rs / parse_string_iter

Function parse_string_iter

arrow-cast/src/cast/string.rs:87–121  ·  view source on GitHub ↗
(
    iter: I,
    cast_options: &CastOptions,
    nulls: F,
)

Source from the content-addressed store, hash-verified

85}
86
87fn parse_string_iter<
88 'a,
89 P: Parser,
90 I: Iterator<Item = Option<&'a str>>,
91 F: FnOnce() -> Option<NullBuffer>,
92>(
93 iter: I,
94 cast_options: &CastOptions,
95 nulls: F,
96) -> Result<ArrayRef, ArrowError> {
97 let array = if cast_options.safe {
98 let iter = iter.map(|x| x.and_then(P::parse));
99
100 // Benefit:
101 // 20% performance improvement
102 // Soundness:
103 // The iterator is trustedLen because it comes from an `StringArray`.
104 unsafe { PrimitiveArray::<P>::from_trusted_len_iter(iter) }
105 } else {
106 let v = iter
107 .map(|x| match x {
108 Some(v) => P::parse(v).ok_or_else(|| {
109 ArrowError::CastError(format!(
110 "Cannot cast string '{v}' to value of {} type",
111 P::DATA_TYPE
112 ))
113 }),
114 None => Ok(P::Native::default()),
115 })
116 .collect::<Result<Vec<_>, ArrowError>>()?;
117 PrimitiveArray::try_new(v.into(), nulls())?
118 };
119
120 Ok(Arc::new(array) as ArrayRef)
121}
122
123/// Casts generic string arrays to an ArrowTimestampType (TimeStampNanosecondArray, etc.)
124pub(crate) fn cast_string_to_timestamp<O: OffsetSizeTrait, T: ArrowTimestampType>(

Callers

nothing calls this directly

Calls 4

defaultFunction · 0.85
try_newFunction · 0.85
and_thenMethod · 0.80
parseFunction · 0.50

Tested by

no test coverage detected