Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Made IPC IO use try_new #879

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct MutableBinaryArray<O: Offset> {

impl<O: Offset> From<MutableBinaryArray<O>> for BinaryArray<O> {
fn from(other: MutableBinaryArray<O>) -> Self {
BinaryArray::<O>::from_data(
BinaryArray::<O>::new(
other.data_type,
other.offsets.into(),
other.values.into(),
Expand Down Expand Up @@ -179,7 +179,7 @@ impl<O: Offset> MutableArray for MutableBinaryArray<O> {
}

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(BinaryArray::from_data(
Box::new(BinaryArray::new(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
std::mem::take(&mut self.values).into(),
Expand All @@ -188,7 +188,7 @@ impl<O: Offset> MutableArray for MutableBinaryArray<O> {
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(BinaryArray::from_data(
Arc::new(BinaryArray::new(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
std::mem::take(&mut self.values).into(),
Expand Down
2 changes: 1 addition & 1 deletion src/array/boolean/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ impl<A: ffi::ArrowArrayRef> FromFfi<A> for BooleanArray {
let data_type = array.data_type().clone();
let validity = unsafe { array.validity() }?;
let values = unsafe { array.bitmap(1) }?;
Ok(Self::from_data(data_type, values, validity))
Self::try_new(data_type, values, validity)
}
}
14 changes: 5 additions & 9 deletions src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ impl BooleanArray {

/// Returns a new empty [`BooleanArray`].
pub fn new_empty(data_type: DataType) -> Self {
Self::from_data(data_type, Bitmap::new(), None)
Self::new(data_type, Bitmap::new(), None)
}

/// Returns a new [`BooleanArray`] whose all slots are null / `None`.
pub fn new_null(data_type: DataType, length: usize) -> Self {
let bitmap = Bitmap::new_zeroed(length);
Self::from_data(data_type, bitmap.clone(), Some(bitmap))
Self::new(data_type, bitmap.clone(), Some(bitmap))
}
}

Expand Down Expand Up @@ -139,13 +139,9 @@ impl BooleanArray {

if let Some(bitmap) = self.validity {
match bitmap.into_mut() {
Left(bitmap) => Left(BooleanArray::from_data(
self.data_type,
self.values,
Some(bitmap),
)),
Left(bitmap) => Left(BooleanArray::new(self.data_type, self.values, Some(bitmap))),
Right(mutable_bitmap) => match self.values.into_mut() {
Left(immutable) => Left(BooleanArray::from_data(
Left(immutable) => Left(BooleanArray::new(
self.data_type,
immutable,
Some(mutable_bitmap.into()),
Expand All @@ -159,7 +155,7 @@ impl BooleanArray {
}
} else {
match self.values.into_mut() {
Left(immutable) => Left(BooleanArray::from_data(self.data_type, immutable, None)),
Left(immutable) => Left(BooleanArray::new(self.data_type, immutable, None)),
Right(mutable) => Right(MutableBooleanArray::from_data(
self.data_type,
mutable,
Expand Down
2 changes: 1 addition & 1 deletion src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct MutableBooleanArray {

impl From<MutableBooleanArray> for BooleanArray {
fn from(other: MutableBooleanArray) -> Self {
BooleanArray::from_data(
BooleanArray::new(
other.data_type,
other.values.into(),
other.validity.map(|x| x.into()),
Expand Down
2 changes: 1 addition & 1 deletion src/array/dictionary/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<K: DictionaryKey, A: ffi::ArrowArrayRef> FromFfi<A> for DictionaryArray<K>
let values = unsafe { array.buffer::<K>(1) }?;

let data_type = K::PRIMITIVE.into();
let keys = PrimitiveArray::<K>::from_data(data_type, values, validity);
let keys = PrimitiveArray::<K>::try_new(data_type, values, validity)?;
let values = array.dictionary()?.unwrap();
let values = ffi::try_from(values)?.into();

Expand Down
2 changes: 1 addition & 1 deletion src/array/fixed_size_binary/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ impl<A: ffi::ArrowArrayRef> FromFfi<A> for FixedSizeBinaryArray {
let validity = unsafe { array.validity() }?;
let values = unsafe { array.buffer::<u8>(1) }?;

Ok(Self::from_data(data_type, values, validity))
Self::try_new(data_type, values, validity)
}
}
4 changes: 2 additions & 2 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ impl FixedSizeBinaryArray {

/// Returns a new empty [`FixedSizeBinaryArray`].
pub fn new_empty(data_type: DataType) -> Self {
Self::from_data(data_type, Buffer::new(), None)
Self::new(data_type, Buffer::new(), None)
}

/// Returns a new null [`FixedSizeBinaryArray`].
pub fn new_null(data_type: DataType, length: usize) -> Self {
Self::from_data(
Self::new(
data_type,
Buffer::new_zeroed(length),
Some(Bitmap::new_zeroed(length)),
Expand Down
6 changes: 3 additions & 3 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct MutableFixedSizeBinaryArray {

impl From<MutableFixedSizeBinaryArray> for FixedSizeBinaryArray {
fn from(other: MutableFixedSizeBinaryArray) -> Self {
FixedSizeBinaryArray::from_data(
FixedSizeBinaryArray::new(
other.data_type,
other.values.into(),
other.validity.map(|x| x.into()),
Expand Down Expand Up @@ -187,15 +187,15 @@ impl MutableArray for MutableFixedSizeBinaryArray {
}

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(FixedSizeBinaryArray::from_data(
Box::new(FixedSizeBinaryArray::new(
DataType::FixedSizeBinary(self.size),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(FixedSizeBinaryArray::from_data(
Arc::new(FixedSizeBinaryArray::new(
DataType::FixedSizeBinary(self.size),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
Expand Down
2 changes: 1 addition & 1 deletion src/array/fixed_size_list/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ impl<A: ffi::ArrowArrayRef> FromFfi<A> for FixedSizeListArray {
let child = unsafe { array.child(0)? };
let values = ffi::try_from(child)?.into();

Ok(Self::from_data(data_type, values, validity))
Self::try_new(data_type, values, validity)
}
}
4 changes: 2 additions & 2 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl FixedSizeListArray {
pub fn new_empty(data_type: DataType) -> Self {
let values =
new_empty_array(Self::get_child_and_size(&data_type).0.data_type().clone()).into();
Self::from_data(data_type, values, None)
Self::new(data_type, values, None)
}

/// Returns a new null [`FixedSizeListArray`].
Expand All @@ -109,7 +109,7 @@ impl FixedSizeListArray {
length,
)
.into();
Self::from_data(data_type, values, Some(Bitmap::new_zeroed(length)))
Self::new(data_type, values, Some(Bitmap::new_zeroed(length)))
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/array/fixed_size_list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct MutableFixedSizeListArray<M: MutableArray> {

impl<M: MutableArray> From<MutableFixedSizeListArray<M>> for FixedSizeListArray {
fn from(mut other: MutableFixedSizeListArray<M>) -> Self {
FixedSizeListArray::from_data(
FixedSizeListArray::new(
other.data_type,
other.values.as_arc(),
other.validity.map(|x| x.into()),
Expand Down Expand Up @@ -93,15 +93,15 @@ impl<M: MutableArray + 'static> MutableArray for MutableFixedSizeListArray<M> {
}

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(FixedSizeListArray::from_data(
Box::new(FixedSizeListArray::new(
self.data_type.clone(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(FixedSizeListArray::from_data(
Arc::new(FixedSizeListArray::new(
self.data_type.clone(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
Expand Down
4 changes: 2 additions & 2 deletions src/array/growable/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a, O: Offset> GrowableBinary<'a, O> {
let offsets = std::mem::take(&mut self.offsets);
let values = std::mem::take(&mut self.values);

BinaryArray::<O>::from_data(data_type, offsets.into(), values.into(), validity.into())
BinaryArray::<O>::new(data_type, offsets.into(), values.into(), validity.into())
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'a, O: Offset> Growable<'a> for GrowableBinary<'a, O> {

impl<'a, O: Offset> From<GrowableBinary<'a, O>> for BinaryArray<O> {
fn from(val: GrowableBinary<'a, O>) -> Self {
BinaryArray::<O>::from_data(
BinaryArray::<O>::new(
val.data_type,
val.offsets.into(),
val.values.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/array/growable/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> GrowableBoolean<'a> {
let validity = std::mem::take(&mut self.validity);
let values = std::mem::take(&mut self.values);

BooleanArray::from_data(self.data_type.clone(), values.into(), validity.into())
BooleanArray::new(self.data_type.clone(), values.into(), validity.into())
}
}

Expand Down Expand Up @@ -82,6 +82,6 @@ impl<'a> Growable<'a> for GrowableBoolean<'a> {

impl<'a> From<GrowableBoolean<'a>> for BooleanArray {
fn from(val: GrowableBoolean<'a>) -> Self {
BooleanArray::from_data(val.data_type, val.values.into(), val.validity.into())
BooleanArray::new(val.data_type, val.values.into(), val.validity.into())
}
}
4 changes: 2 additions & 2 deletions src/array/growable/fixed_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'a> GrowableFixedSizeBinary<'a> {
let validity = std::mem::take(&mut self.validity);
let values = std::mem::take(&mut self.values);

FixedSizeBinaryArray::from_data(
FixedSizeBinaryArray::new(
self.arrays[0].data_type().clone(),
values.into(),
validity.into(),
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a> Growable<'a> for GrowableFixedSizeBinary<'a> {

impl<'a> From<GrowableFixedSizeBinary<'a>> for FixedSizeBinaryArray {
fn from(val: GrowableFixedSizeBinary<'a>) -> Self {
FixedSizeBinaryArray::from_data(
FixedSizeBinaryArray::new(
val.arrays[0].data_type().clone(),
val.values.into(),
val.validity.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/array/growable/fixed_size_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> GrowableFixedSizeList<'a> {
let validity = std::mem::take(&mut self.validity);
let values = self.values.as_arc();

FixedSizeListArray::from_data(self.arrays[0].data_type().clone(), values, validity.into())
FixedSizeListArray::new(self.arrays[0].data_type().clone(), values, validity.into())
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'a> From<GrowableFixedSizeList<'a>> for FixedSizeListArray {
let mut values = val.values;
let values = values.as_arc();

Self::from_data(
Self::new(
val.arrays[0].data_type().clone(),
values,
val.validity.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/array/growable/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a, O: Offset> GrowableList<'a, O> {
let offsets = std::mem::take(&mut self.offsets);
let values = self.values.as_arc();

ListArray::<O>::from_data(
ListArray::<O>::new(
self.arrays[0].data_type().clone(),
offsets.into(),
values,
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a, O: Offset> From<GrowableList<'a, O>> for ListArray<O> {
let mut values = val.values;
let values = values.as_arc();

ListArray::<O>::from_data(
ListArray::<O>::new(
val.arrays[0].data_type().clone(),
val.offsets.into(),
values,
Expand Down
6 changes: 3 additions & 3 deletions src/array/growable/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ impl<'a> Growable<'a> for GrowableNull {
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(NullArray::from_data(self.data_type.clone(), self.length))
Arc::new(NullArray::new(self.data_type.clone(), self.length))
}

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(NullArray::from_data(self.data_type.clone(), self.length))
Box::new(NullArray::new(self.data_type.clone(), self.length))
}
}

impl From<GrowableNull> for NullArray {
fn from(val: GrowableNull) -> Self {
NullArray::from_data(val.data_type, val.length)
NullArray::new(val.data_type, val.length)
}
}
4 changes: 2 additions & 2 deletions src/array/growable/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, T: NativeType> GrowablePrimitive<'a, T> {
let validity = std::mem::take(&mut self.validity);
let values = std::mem::take(&mut self.values);

PrimitiveArray::<T>::from_data(self.data_type.clone(), values.into(), validity.into())
PrimitiveArray::<T>::new(self.data_type.clone(), values.into(), validity.into())
}
}

Expand Down Expand Up @@ -96,6 +96,6 @@ impl<'a, T: NativeType> Growable<'a> for GrowablePrimitive<'a, T> {
impl<'a, T: NativeType> From<GrowablePrimitive<'a, T>> for PrimitiveArray<T> {
#[inline]
fn from(val: GrowablePrimitive<'a, T>) -> Self {
PrimitiveArray::<T>::from_data(val.data_type, val.values.into(), val.validity.into())
PrimitiveArray::<T>::new(val.data_type, val.values.into(), val.validity.into())
}
}
4 changes: 2 additions & 2 deletions src/array/growable/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> GrowableStruct<'a> {
let values = std::mem::take(&mut self.values);
let values = values.into_iter().map(|mut x| x.as_arc()).collect();

StructArray::from_data(
StructArray::new(
DataType::Struct(self.arrays[0].fields().to_vec()),
values,
validity.into(),
Expand Down Expand Up @@ -120,7 +120,7 @@ impl<'a> From<GrowableStruct<'a>> for StructArray {
fn from(val: GrowableStruct<'a>) -> Self {
let values = val.values.into_iter().map(|mut x| x.as_arc()).collect();

StructArray::from_data(
StructArray::new(
DataType::Struct(val.arrays[0].fields().to_vec()),
values,
val.validity.into(),
Expand Down
6 changes: 3 additions & 3 deletions src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<O: Offset, M: MutableArray + Default> Default for MutableListArray<O, M> {

impl<O: Offset, M: MutableArray> From<MutableListArray<O, M>> for ListArray<O> {
fn from(mut other: MutableListArray<O, M>) -> Self {
ListArray::from_data(
ListArray::new(
other.data_type,
other.offsets.into(),
other.values.as_arc(),
Expand Down Expand Up @@ -209,7 +209,7 @@ impl<O: Offset, M: MutableArray + Default + 'static> MutableArray for MutableLis
}

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(ListArray::from_data(
Box::new(ListArray::new(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
Expand All @@ -218,7 +218,7 @@ impl<O: Offset, M: MutableArray + Default + 'static> MutableArray for MutableLis
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(ListArray::from_data(
Arc::new(ListArray::new(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
Expand Down
2 changes: 1 addition & 1 deletion src/array/map/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ impl<A: ffi::ArrowArrayRef> FromFfi<A> for MapArray {
let child = array.child(0)?;
let values = ffi::try_from(child)?.into();

Ok(Self::from_data(data_type, offsets, values, validity))
Self::try_new(data_type, offsets, values, validity)
}
}
4 changes: 2 additions & 2 deletions src/array/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl MapArray {
/// Returns a new null [`MapArray`] of `length`.
pub fn new_null(data_type: DataType, length: usize) -> Self {
let field = new_empty_array(Self::get_field(&data_type).data_type().clone()).into();
Self::from_data(
Self::new(
data_type,
Buffer::new_zeroed(length + 1),
field,
Expand All @@ -115,7 +115,7 @@ impl MapArray {
/// Returns a new empty [`MapArray`].
pub fn new_empty(data_type: DataType) -> Self {
let field = new_empty_array(Self::get_field(&data_type).data_type().clone()).into();
Self::from_data(data_type, Buffer::from(vec![0i32]), field, None)
Self::new(data_type, Buffer::from(vec![0i32]), field, None)
}
}

Expand Down
Loading