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

Method try_new_from_array_data

arrow-array/src/array/map_array.rs:274–324  ·  view source on GitHub ↗
(data: ArrayData)

Source from the content-addressed store, hash-verified

272
273impl MapArray {
274 fn try_new_from_array_data(data: ArrayData) -> Result<Self, ArrowError> {
275 let (data_type, len, nulls, offset, mut buffers, mut child_data) = data.into_parts();
276
277 if !matches!(data_type, DataType::Map(_, _)) {
278 return Err(ArrowError::InvalidArgumentError(format!(
279 "MapArray expected ArrayData with DataType::Map got {data_type}",
280 )));
281 }
282
283 if buffers.len() != 1 {
284 return Err(ArrowError::InvalidArgumentError(format!(
285 "MapArray data should contain a single buffer only (value offsets), had {}",
286 buffers.len(),
287 )));
288 }
289 let buffer = buffers.pop().expect("checked above");
290
291 if child_data.len() != 1 {
292 return Err(ArrowError::InvalidArgumentError(format!(
293 "MapArray should contain a single child array (values array), had {}",
294 child_data.len()
295 )));
296 }
297 let entries = child_data.pop().expect("checked above");
298
299 if let DataType::Struct(fields) = entries.data_type() {
300 if fields.len() != 2 {
301 return Err(ArrowError::InvalidArgumentError(format!(
302 "MapArray should contain a struct array with 2 fields, have {} fields",
303 fields.len()
304 )));
305 }
306 } else {
307 return Err(ArrowError::InvalidArgumentError(format!(
308 "MapArray should contain a struct array child, found {:?}",
309 entries.data_type()
310 )));
311 }
312 let entries = entries.into();
313
314 // SAFETY:
315 // ArrayData is valid, and verified type above
316 let value_offsets = unsafe { get_offsets_from_buffer(buffer, offset, len) };
317
318 Ok(Self {
319 data_type,
320 nulls,
321 entries,
322 value_offsets,
323 })
324 }
325
326 /// Creates map array from provided keys, values and entry_offsets.
327 pub fn new_from_strings<'a>(

Callers

nothing calls this directly

Calls 4

get_offsets_from_bufferFunction · 0.85
into_partsMethod · 0.45
lenMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected