Skip to content

Commit 3717507

Browse files
authored
Merge branch 'main' into alamb/union_array
2 parents ff4a428 + 91b1405 commit 3717507

File tree

6 files changed

+1060
-38
lines changed

6 files changed

+1060
-38
lines changed

arrow-array/src/array/dictionary_array.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
};
2626
use arrow_buffer::bit_util::set_bit;
2727
use arrow_buffer::buffer::NullBuffer;
28-
use arrow_buffer::{ArrowNativeType, BooleanBuffer, BooleanBufferBuilder};
28+
use arrow_buffer::{ArrowNativeType, BooleanBuffer, BooleanBufferBuilder, ScalarBuffer};
2929
use arrow_data::ArrayData;
3030
use arrow_schema::{ArrowError, DataType};
3131
use std::any::Any;
@@ -580,21 +580,25 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
580580
}
581581
}
582582

583-
/// Constructs a `DictionaryArray` from an array data reference.
583+
/// Constructs a `DictionaryArray` from an `ArrayData`
584584
impl<T: ArrowDictionaryKeyType> From<ArrayData> for DictionaryArray<T> {
585585
fn from(data: ArrayData) -> Self {
586+
let (data_type, len, nulls, offset, mut buffers, mut child_data) = data.into_parts();
587+
586588
assert_eq!(
587-
data.buffers().len(),
589+
buffers.len(),
588590
1,
589591
"DictionaryArray data should contain a single buffer only (keys)."
590592
);
593+
let buffer = buffers.pop().expect("checked above");
591594
assert_eq!(
592-
data.child_data().len(),
595+
child_data.len(),
593596
1,
594597
"DictionaryArray should contain a single child array (values)."
595598
);
599+
let cd = child_data.pop().expect("checked above");
596600

597-
if let DataType::Dictionary(key_data_type, _) = data.data_type() {
601+
if let DataType::Dictionary(key_data_type, _) = &data_type {
598602
assert_eq!(
599603
&T::DATA_TYPE,
600604
key_data_type.as_ref(),
@@ -603,19 +607,10 @@ impl<T: ArrowDictionaryKeyType> From<ArrayData> for DictionaryArray<T> {
603607
key_data_type
604608
);
605609

606-
let values = make_array(data.child_data()[0].clone());
607-
let data_type = data.data_type().clone();
610+
let values = make_array(cd);
608611

609612
// create a zero-copy of the keys' data
610-
// SAFETY:
611-
// ArrayData is valid and verified type above
612-
613-
let keys = PrimitiveArray::<T>::from(unsafe {
614-
data.into_builder()
615-
.data_type(T::DATA_TYPE)
616-
.child_data(vec![])
617-
.build_unchecked()
618-
});
613+
let keys = PrimitiveArray::<T>::new(ScalarBuffer::new(buffer, offset, len), nulls);
619614

620615
Self {
621616
data_type,

arrow-array/src/array/null_array.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,19 @@ impl Array for NullArray {
138138

139139
impl From<ArrayData> for NullArray {
140140
fn from(data: ArrayData) -> Self {
141+
let (data_type, len, nulls, _offset, buffers, _child_data) = data.into_parts();
142+
141143
assert_eq!(
142-
data.data_type(),
143-
&DataType::Null,
144+
data_type,
145+
DataType::Null,
144146
"NullArray data type should be Null"
145147
);
146-
assert_eq!(
147-
data.buffers().len(),
148-
0,
149-
"NullArray data should contain 0 buffers"
150-
);
148+
assert_eq!(buffers.len(), 0, "NullArray data should contain 0 buffers");
151149
assert!(
152-
data.nulls().is_none(),
150+
nulls.is_none(),
153151
"NullArray data should not contain a null buffer, as no buffers are required"
154152
);
155-
Self { len: data.len() }
153+
Self { len }
156154
}
157155
}
158156

arrow-array/src/array/primitive_array.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,18 +1597,21 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
15971597
/// Constructs a `PrimitiveArray` from an array data reference.
15981598
impl<T: ArrowPrimitiveType> From<ArrayData> for PrimitiveArray<T> {
15991599
fn from(data: ArrayData) -> Self {
1600-
Self::assert_compatible(data.data_type());
1600+
let (data_type, len, nulls, offset, mut buffers, _child_data) = data.into_parts();
1601+
1602+
Self::assert_compatible(&data_type);
16011603
assert_eq!(
1602-
data.buffers().len(),
1604+
buffers.len(),
16031605
1,
16041606
"PrimitiveArray data should contain a single buffer only (values buffer)"
16051607
);
1608+
let buffer = buffers.pop().expect("checked above");
16061609

1607-
let values = ScalarBuffer::new(data.buffers()[0].clone(), data.offset(), data.len());
1610+
let values = ScalarBuffer::new(buffer, offset, len);
16081611
Self {
1609-
data_type: data.data_type().clone(),
1612+
data_type,
16101613
values,
1611-
nulls: data.nulls().cloned(),
1614+
nulls,
16121615
}
16131616
}
16141617
}

0 commit comments

Comments
 (0)