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

Method from_iter

arrow-array/src/array/primitive_array.rs:1456–1479  ·  view source on GitHub ↗
(iter: I)

Source from the content-addressed store, hash-verified

1454
1455impl<T: ArrowPrimitiveType, Ptr: Into<NativeAdapter<T>>> FromIterator<Ptr> for PrimitiveArray<T> {
1456 fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self {
1457 let iter = iter.into_iter();
1458 let (lower, _) = iter.size_hint();
1459
1460 let mut null_builder = NullBufferBuilder::new(lower);
1461
1462 let buffer: Buffer = iter
1463 .map(|item| {
1464 if let Some(a) = item.into().native {
1465 null_builder.append_non_null();
1466 a
1467 } else {
1468 null_builder.append_null();
1469 // this ensures that null items on the buffer are not arbitrary.
1470 // This is important because fallible operations can use null values (e.g. a vectorized "add")
1471 // which may panic (e.g. overflow if the number on the slots happen to be very large).
1472 T::Native::default()
1473 }
1474 })
1475 .collect();
1476
1477 let maybe_nulls = null_builder.finish();
1478 PrimitiveArray::new(ScalarBuffer::from(buffer), maybe_nulls)
1479 }
1480}
1481
1482impl<T: ArrowPrimitiveType> PrimitiveArray<T> {

Callers

nothing calls this directly

Calls 7

defaultFunction · 0.85
collectMethod · 0.80
append_non_nullMethod · 0.80
into_iterMethod · 0.45
size_hintMethod · 0.45
append_nullMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected