Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::timezone::Tz;
use crate::trusted_len::trusted_len_unzip;
use crate::types::*;
use crate::{Array, ArrayAccessor, ArrayRef, Scalar};
use arrow_buffer::{ArrowNativeType, Buffer, NullBuffer, ScalarBuffer, i256};
use arrow_buffer::{ArrowNativeType, Buffer, NullBuffer, NullBufferBuilder, ScalarBuffer, i256};
use arrow_data::bit_iterator::try_for_each_valid_idx;
use arrow_data::{ArrayData, ArrayDataBuilder};
use arrow_schema::{ArrowError, DataType};
Expand Down Expand Up @@ -1450,15 +1450,15 @@ impl<T: ArrowPrimitiveType, Ptr: Into<NativeAdapter<T>>> FromIterator<Ptr> for P
let iter = iter.into_iter();
let (lower, _) = iter.size_hint();

let mut null_builder = BooleanBufferBuilder::new(lower);
let mut null_builder = NullBufferBuilder::new(lower);

let buffer: Buffer = iter
.map(|item| {
if let Some(a) = item.into().native {
null_builder.append(true);
null_builder.append_non_null();
a
} else {
null_builder.append(false);
null_builder.append_null();
// this ensures that null items on the buffer are not arbitrary.
// This is important because fallible operations can use null values (e.g. a vectorized "add")
// which may panic (e.g. overflow if the number on the slots happen to be very large).
Expand All @@ -1467,20 +1467,8 @@ impl<T: ArrowPrimitiveType, Ptr: Into<NativeAdapter<T>>> FromIterator<Ptr> for P
})
.collect();

let len = null_builder.len();

let data = unsafe {
ArrayData::new_unchecked(
T::DATA_TYPE,
len,
None,
Some(null_builder.into()),
0,
vec![buffer],
vec![],
)
};
PrimitiveArray::from(data)
let maybe_nulls = null_builder.finish();
PrimitiveArray::new(ScalarBuffer::from(buffer), maybe_nulls)
}
}

Expand Down
Loading