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

Method try_new_with_length

arrow-array/src/array/struct_array.rs:127–189  ·  view source on GitHub ↗

Create a new [`StructArray`] from the provided parts, returning an error on failure # Errors Errors if `fields.len() != arrays.len()` `fields[i].data_type() != arrays[i].data_type()` `arrays[i].len() != arrays[j].len()` `arrays[i].len() != nulls.len()` `!fields[i].is_nullable() && !nulls.contains(arrays[i].nulls())`

(
        fields: Fields,
        arrays: Vec<ArrayRef>,
        nulls: Option<NullBuffer>,
        len: usize,
    )

Source from the content-addressed store, hash-verified

125 /// * `arrays[i].len() != nulls.len()`
126 /// * `!fields[i].is_nullable() && !nulls.contains(arrays[i].nulls())`
127 pub fn try_new_with_length(
128 fields: Fields,
129 arrays: Vec<ArrayRef>,
130 nulls: Option<NullBuffer>,
131 len: usize,
132 ) -> Result<Self, ArrowError> {
133 if fields.len() != arrays.len() {
134 return Err(ArrowError::InvalidArgumentError(format!(
135 "Incorrect number of arrays for StructArray fields, expected {} got {}",
136 fields.len(),
137 arrays.len()
138 )));
139 }
140
141 if let Some(n) = nulls.as_ref() {
142 if n.len() != len {
143 return Err(ArrowError::InvalidArgumentError(format!(
144 "Incorrect number of nulls for StructArray, expected {len} got {}",
145 n.len(),
146 )));
147 }
148 }
149
150 for (f, a) in fields.iter().zip(&arrays) {
151 if f.data_type() != a.data_type() {
152 return Err(ArrowError::InvalidArgumentError(format!(
153 "Incorrect datatype for StructArray field {:?}, expected {} got {}",
154 f.name(),
155 f.data_type(),
156 a.data_type()
157 )));
158 }
159
160 if a.len() != len {
161 return Err(ArrowError::InvalidArgumentError(format!(
162 "Incorrect array length for StructArray field {:?}, expected {} got {}",
163 f.name(),
164 len,
165 a.len()
166 )));
167 }
168
169 if !f.is_nullable() {
170 if let Some(a) = a.logical_nulls() {
171 if !nulls.as_ref().map(|n| n.contains(&a)).unwrap_or_default()
172 && a.null_count() > 0
173 {
174 return Err(ArrowError::InvalidArgumentError(format!(
175 "Found unmasked nulls for non-nullable StructArray field {:?}",
176 f.name()
177 )));
178 }
179 }
180 }
181 }
182
183 Ok(Self {
184 len,

Callers

nothing calls this directly

Calls 10

zipMethod · 0.80
filterMethod · 0.80
lenMethod · 0.45
as_refMethod · 0.45
iterMethod · 0.45
data_typeMethod · 0.45
is_nullableMethod · 0.45
logical_nullsMethod · 0.45
containsMethod · 0.45
null_countMethod · 0.45

Tested by

no test coverage detected