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

Method with_capacities

arrow-data/src/transform/mod.rs:414–717  ·  view source on GitHub ↗

Similar to [MutableArrayData::new], but lets users define the preallocated capacities of the array with more granularity. See [MutableArrayData::new] for more information on the arguments. # Panics This function panics if the given `capacities` don't match the data type of `arrays`. Or when a [Capacities] variant is not yet supported.

(
        arrays: Vec<&'a ArrayData>,
        use_nulls: bool,
        capacities: Capacities,
    )

Source from the content-addressed store, hash-verified

412 /// This function panics if the given `capacities` don't match the data type
413 /// of `arrays`. Or when a [Capacities] variant is not yet supported.
414 pub fn with_capacities(
415 arrays: Vec<&'a ArrayData>,
416 use_nulls: bool,
417 capacities: Capacities,
418 ) -> Self {
419 let data_type = arrays[0].data_type();
420
421 for a in arrays.iter().skip(1) {
422 assert_eq!(
423 data_type,
424 a.data_type(),
425 "Arrays with inconsistent types passed to MutableArrayData"
426 )
427 }
428
429 // if any of the arrays has nulls, insertions from any array requires setting bits
430 // as there is at least one array with nulls.
431 let use_nulls = use_nulls | arrays.iter().any(|array| array.null_count() > 0);
432
433 let mut array_capacity;
434
435 let [buffer1, buffer2] = match (data_type, &capacities) {
436 (
437 DataType::LargeUtf8 | DataType::LargeBinary,
438 Capacities::Binary(capacity, Some(value_cap)),
439 ) => {
440 array_capacity = *capacity;
441 preallocate_offset_and_binary_buffer::<i64>(*capacity, *value_cap)
442 }
443 (DataType::Utf8 | DataType::Binary, Capacities::Binary(capacity, Some(value_cap))) => {
444 array_capacity = *capacity;
445 preallocate_offset_and_binary_buffer::<i32>(*capacity, *value_cap)
446 }
447 (_, Capacities::Array(capacity)) => {
448 array_capacity = *capacity;
449 new_buffers(data_type, *capacity)
450 }
451 (
452 DataType::List(_)
453 | DataType::LargeList(_)
454 | DataType::ListView(_)
455 | DataType::LargeListView(_)
456 | DataType::FixedSizeList(_, _),
457 Capacities::List(capacity, _),
458 ) => {
459 array_capacity = *capacity;
460 new_buffers(data_type, *capacity)
461 }
462 _ => panic!("Capacities: {capacities:?} not yet supported"),
463 };
464
465 let child_data = match &data_type {
466 DataType::Decimal32(_, _)
467 | DataType::Decimal64(_, _)
468 | DataType::Decimal128(_, _)
469 | DataType::Decimal256(_, _)
470 | DataType::Null
471 | DataType::Boolean

Callers

nothing calls this directly

Calls 15

new_buffersFunction · 0.85
build_extend_nullsFunction · 0.85
build_extend_null_bitsFunction · 0.85
build_extend_dictionaryFunction · 0.85
build_extend_viewFunction · 0.85
child_dataMethod · 0.80
zipMethod · 0.80
allMethod · 0.80
collectMethod · 0.80
freezeMethod · 0.80
build_extendFunction · 0.70
ArrayClass · 0.50

Tested by

no test coverage detected