From 9a78ba419168cd3e2cbb359a2156893db2706c68 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Thu, 3 Mar 2022 05:58:07 +0000 Subject: [PATCH] Made IO use try_new --- src/array/binary/mutable.rs | 6 +- src/array/boolean/ffi.rs | 2 +- src/array/boolean/mod.rs | 14 ++-- src/array/boolean/mutable.rs | 2 +- src/array/dictionary/ffi.rs | 2 +- src/array/fixed_size_binary/ffi.rs | 2 +- src/array/fixed_size_binary/mod.rs | 4 +- src/array/fixed_size_binary/mutable.rs | 6 +- src/array/fixed_size_list/ffi.rs | 2 +- src/array/fixed_size_list/mod.rs | 4 +- src/array/fixed_size_list/mutable.rs | 6 +- src/array/growable/binary.rs | 4 +- src/array/growable/boolean.rs | 4 +- src/array/growable/fixed_binary.rs | 4 +- src/array/growable/fixed_size_list.rs | 4 +- src/array/growable/list.rs | 4 +- src/array/growable/null.rs | 6 +- src/array/growable/primitive.rs | 4 +- src/array/growable/structure.rs | 4 +- src/array/list/mutable.rs | 6 +- src/array/map/ffi.rs | 2 +- src/array/map/mod.rs | 4 +- src/array/null.rs | 6 +- src/array/primitive/ffi.rs | 2 +- src/array/primitive/from_natural.rs | 6 +- src/array/primitive/mutable.rs | 6 +- src/array/struct_/ffi.rs | 2 +- src/array/union/ffi.rs | 2 +- src/array/union/mod.rs | 2 +- src/array/utf8/mod.rs | 66 ++++++++++++------- src/compute/arithmetics/decimal/add.rs | 2 +- src/compute/arithmetics/decimal/div.rs | 2 +- src/compute/arithmetics/decimal/mul.rs | 2 +- src/compute/arithmetics/decimal/sub.rs | 2 +- src/compute/arity.rs | 16 ++--- src/compute/boolean.rs | 12 ++-- src/compute/boolean_kleene.rs | 12 ++-- src/compute/cast/binary_to.rs | 4 +- src/compute/cast/boolean_to.rs | 2 +- src/compute/cast/decimal_to.rs | 2 +- src/compute/cast/mod.rs | 9 ++- src/compute/cast/primitive_to.rs | 4 +- src/compute/comparison/binary.rs | 4 +- src/compute/comparison/boolean.rs | 8 +-- src/compute/comparison/mod.rs | 16 ++--- src/compute/comparison/primitive.rs | 4 +- src/compute/comparison/utf8.rs | 4 +- src/compute/contains.rs | 6 +- src/compute/filter.rs | 6 +- src/compute/hash.rs | 6 +- src/compute/length.rs | 2 +- src/compute/like.rs | 8 +-- src/compute/nullif.rs | 4 +- src/compute/regex_match.rs | 8 +-- src/compute/sort/boolean.rs | 2 +- src/compute/sort/common.rs | 2 +- src/compute/sort/lex_sort.rs | 6 +- src/compute/sort/mod.rs | 2 +- src/compute/sort/primitive/sort.rs | 2 +- src/compute/substring.rs | 2 +- src/compute/take/binary.rs | 2 +- src/compute/take/boolean.rs | 2 +- src/compute/take/mod.rs | 2 +- src/compute/take/primitive.rs | 2 +- src/compute/take/structure.rs | 2 +- src/io/avro/read/nested.rs | 8 +-- src/io/ipc/read/array/binary.rs | 4 +- src/io/ipc/read/array/boolean.rs | 2 +- src/io/ipc/read/array/fixed_size_binary.rs | 2 +- src/io/ipc/read/array/fixed_size_list.rs | 2 +- src/io/ipc/read/array/list.rs | 2 +- src/io/ipc/read/array/map.rs | 2 +- src/io/ipc/read/array/null.rs | 5 +- src/io/ipc/read/array/primitive.rs | 2 +- src/io/ipc/read/array/struct_.rs | 2 +- src/io/ipc/read/array/union.rs | 2 +- src/io/ipc/read/array/utf8.rs | 4 +- src/io/json/read/deserialize.rs | 6 +- src/io/json_integration/read/array.rs | 32 ++++----- .../parquet/read/deserialize/boolean/basic.rs | 2 +- .../read/deserialize/boolean/nested.rs | 2 +- .../deserialize/fixed_size_binary/basic.rs | 2 +- src/io/parquet/read/deserialize/mod.rs | 6 +- src/io/parquet/read/deserialize/null.rs | 4 +- .../read/deserialize/primitive/dictionary.rs | 2 +- src/io/parquet/read/deserialize/simple.rs | 6 +- src/io/parquet/write/mod.rs | 16 ++--- 87 files changed, 227 insertions(+), 247 deletions(-) diff --git a/src/array/binary/mutable.rs b/src/array/binary/mutable.rs index f39fa62c818..1a824193dcf 100644 --- a/src/array/binary/mutable.rs +++ b/src/array/binary/mutable.rs @@ -25,7 +25,7 @@ pub struct MutableBinaryArray { impl From> for BinaryArray { fn from(other: MutableBinaryArray) -> Self { - BinaryArray::::from_data( + BinaryArray::::new( other.data_type, other.offsets.into(), other.values.into(), @@ -179,7 +179,7 @@ impl MutableArray for MutableBinaryArray { } fn as_box(&mut self) -> Box { - 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(), @@ -188,7 +188,7 @@ impl MutableArray for MutableBinaryArray { } fn as_arc(&mut self) -> Arc { - 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(), diff --git a/src/array/boolean/ffi.rs b/src/array/boolean/ffi.rs index 9998e8f00e1..da7482c11e2 100644 --- a/src/array/boolean/ffi.rs +++ b/src/array/boolean/ffi.rs @@ -53,6 +53,6 @@ impl FromFfi 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) } } diff --git a/src/array/boolean/mod.rs b/src/array/boolean/mod.rs index 4ee5ccfa33e..e55fa89c259 100644 --- a/src/array/boolean/mod.rs +++ b/src/array/boolean/mod.rs @@ -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)) } } @@ -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()), @@ -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, diff --git a/src/array/boolean/mutable.rs b/src/array/boolean/mutable.rs index 4be1d19c603..2e52a411e01 100644 --- a/src/array/boolean/mutable.rs +++ b/src/array/boolean/mutable.rs @@ -24,7 +24,7 @@ pub struct MutableBooleanArray { impl From for BooleanArray { fn from(other: MutableBooleanArray) -> Self { - BooleanArray::from_data( + BooleanArray::new( other.data_type, other.values.into(), other.validity.map(|x| x.into()), diff --git a/src/array/dictionary/ffi.rs b/src/array/dictionary/ffi.rs index 65805e46b85..b1159ebd685 100644 --- a/src/array/dictionary/ffi.rs +++ b/src/array/dictionary/ffi.rs @@ -31,7 +31,7 @@ impl FromFfi for DictionaryArray let values = unsafe { array.buffer::(1) }?; let data_type = K::PRIMITIVE.into(); - let keys = PrimitiveArray::::from_data(data_type, values, validity); + let keys = PrimitiveArray::::try_new(data_type, values, validity)?; let values = array.dictionary()?.unwrap(); let values = ffi::try_from(values)?.into(); diff --git a/src/array/fixed_size_binary/ffi.rs b/src/array/fixed_size_binary/ffi.rs index 7728045c0f4..1bb07d322bf 100644 --- a/src/array/fixed_size_binary/ffi.rs +++ b/src/array/fixed_size_binary/ffi.rs @@ -54,6 +54,6 @@ impl FromFfi for FixedSizeBinaryArray { let validity = unsafe { array.validity() }?; let values = unsafe { array.buffer::(1) }?; - Ok(Self::from_data(data_type, values, validity)) + Self::try_new(data_type, values, validity) } } diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 935fbd4ac54..98dc365ff33 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -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)), diff --git a/src/array/fixed_size_binary/mutable.rs b/src/array/fixed_size_binary/mutable.rs index d7b28883c85..a5da541cc86 100644 --- a/src/array/fixed_size_binary/mutable.rs +++ b/src/array/fixed_size_binary/mutable.rs @@ -23,7 +23,7 @@ pub struct MutableFixedSizeBinaryArray { impl From for FixedSizeBinaryArray { fn from(other: MutableFixedSizeBinaryArray) -> Self { - FixedSizeBinaryArray::from_data( + FixedSizeBinaryArray::new( other.data_type, other.values.into(), other.validity.map(|x| x.into()), @@ -187,7 +187,7 @@ impl MutableArray for MutableFixedSizeBinaryArray { } fn as_box(&mut self) -> Box { - 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()), @@ -195,7 +195,7 @@ impl MutableArray for MutableFixedSizeBinaryArray { } fn as_arc(&mut self) -> Arc { - 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()), diff --git a/src/array/fixed_size_list/ffi.rs b/src/array/fixed_size_list/ffi.rs index 5e862f56b48..872c7459869 100644 --- a/src/array/fixed_size_list/ffi.rs +++ b/src/array/fixed_size_list/ffi.rs @@ -40,6 +40,6 @@ impl FromFfi 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) } } diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index 61ac7970f88..c0a48d32f4a 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -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`]. @@ -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))) } } diff --git a/src/array/fixed_size_list/mutable.rs b/src/array/fixed_size_list/mutable.rs index 9c0644a59d1..450a1c9d156 100644 --- a/src/array/fixed_size_list/mutable.rs +++ b/src/array/fixed_size_list/mutable.rs @@ -20,7 +20,7 @@ pub struct MutableFixedSizeListArray { impl From> for FixedSizeListArray { fn from(mut other: MutableFixedSizeListArray) -> Self { - FixedSizeListArray::from_data( + FixedSizeListArray::new( other.data_type, other.values.as_arc(), other.validity.map(|x| x.into()), @@ -93,7 +93,7 @@ impl MutableArray for MutableFixedSizeListArray { } fn as_box(&mut self) -> Box { - 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()), @@ -101,7 +101,7 @@ impl MutableArray for MutableFixedSizeListArray { } fn as_arc(&mut self) -> Arc { - 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()), diff --git a/src/array/growable/binary.rs b/src/array/growable/binary.rs index e4cb2f32a2a..c3403877e9e 100644 --- a/src/array/growable/binary.rs +++ b/src/array/growable/binary.rs @@ -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::::from_data(data_type, offsets.into(), values.into(), validity.into()) + BinaryArray::::new(data_type, offsets.into(), values.into(), validity.into()) } } @@ -99,7 +99,7 @@ impl<'a, O: Offset> Growable<'a> for GrowableBinary<'a, O> { impl<'a, O: Offset> From> for BinaryArray { fn from(val: GrowableBinary<'a, O>) -> Self { - BinaryArray::::from_data( + BinaryArray::::new( val.data_type, val.offsets.into(), val.values.into(), diff --git a/src/array/growable/boolean.rs b/src/array/growable/boolean.rs index 1ab512ceacc..994f5b4e92e 100644 --- a/src/array/growable/boolean.rs +++ b/src/array/growable/boolean.rs @@ -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()) } } @@ -82,6 +82,6 @@ impl<'a> Growable<'a> for GrowableBoolean<'a> { impl<'a> From> 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()) } } diff --git a/src/array/growable/fixed_binary.rs b/src/array/growable/fixed_binary.rs index fc0d958af13..d096ff5a51f 100644 --- a/src/array/growable/fixed_binary.rs +++ b/src/array/growable/fixed_binary.rs @@ -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(), @@ -89,7 +89,7 @@ impl<'a> Growable<'a> for GrowableFixedSizeBinary<'a> { impl<'a> From> 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(), diff --git a/src/array/growable/fixed_size_list.rs b/src/array/growable/fixed_size_list.rs index 09b72a88dc5..1986120efe6 100644 --- a/src/array/growable/fixed_size_list.rs +++ b/src/array/growable/fixed_size_list.rs @@ -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()) } } @@ -99,7 +99,7 @@ impl<'a> From> 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(), diff --git a/src/array/growable/list.rs b/src/array/growable/list.rs index 63d8f22d576..a7eb57eb2c4 100644 --- a/src/array/growable/list.rs +++ b/src/array/growable/list.rs @@ -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::::from_data( + ListArray::::new( self.arrays[0].data_type().clone(), offsets.into(), values, @@ -139,7 +139,7 @@ impl<'a, O: Offset> From> for ListArray { let mut values = val.values; let values = values.as_arc(); - ListArray::::from_data( + ListArray::::new( val.arrays[0].data_type().clone(), val.offsets.into(), values, diff --git a/src/array/growable/null.rs b/src/array/growable/null.rs index b96707870a3..208a389a7fc 100644 --- a/src/array/growable/null.rs +++ b/src/array/growable/null.rs @@ -39,16 +39,16 @@ impl<'a> Growable<'a> for GrowableNull { } fn as_arc(&mut self) -> Arc { - 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 { - Box::new(NullArray::from_data(self.data_type.clone(), self.length)) + Box::new(NullArray::new(self.data_type.clone(), self.length)) } } impl From for NullArray { fn from(val: GrowableNull) -> Self { - NullArray::from_data(val.data_type, val.length) + NullArray::new(val.data_type, val.length) } } diff --git a/src/array/growable/primitive.rs b/src/array/growable/primitive.rs index d64bab94443..19a949e0f9d 100644 --- a/src/array/growable/primitive.rs +++ b/src/array/growable/primitive.rs @@ -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::::from_data(self.data_type.clone(), values.into(), validity.into()) + PrimitiveArray::::new(self.data_type.clone(), values.into(), validity.into()) } } @@ -96,6 +96,6 @@ impl<'a, T: NativeType> Growable<'a> for GrowablePrimitive<'a, T> { impl<'a, T: NativeType> From> for PrimitiveArray { #[inline] fn from(val: GrowablePrimitive<'a, T>) -> Self { - PrimitiveArray::::from_data(val.data_type, val.values.into(), val.validity.into()) + PrimitiveArray::::new(val.data_type, val.values.into(), val.validity.into()) } } diff --git a/src/array/growable/structure.rs b/src/array/growable/structure.rs index bf487dd0fd8..4a7ac0669da 100644 --- a/src/array/growable/structure.rs +++ b/src/array/growable/structure.rs @@ -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(), @@ -120,7 +120,7 @@ impl<'a> From> 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(), diff --git a/src/array/list/mutable.rs b/src/array/list/mutable.rs index 23e4aae5121..47695a7f009 100644 --- a/src/array/list/mutable.rs +++ b/src/array/list/mutable.rs @@ -50,7 +50,7 @@ impl Default for MutableListArray { impl From> for ListArray { fn from(mut other: MutableListArray) -> Self { - ListArray::from_data( + ListArray::new( other.data_type, other.offsets.into(), other.values.as_arc(), @@ -209,7 +209,7 @@ impl MutableArray for MutableLis } fn as_box(&mut self) -> Box { - Box::new(ListArray::from_data( + Box::new(ListArray::new( self.data_type.clone(), std::mem::take(&mut self.offsets).into(), self.values.as_arc(), @@ -218,7 +218,7 @@ impl MutableArray for MutableLis } fn as_arc(&mut self) -> Arc { - Arc::new(ListArray::from_data( + Arc::new(ListArray::new( self.data_type.clone(), std::mem::take(&mut self.offsets).into(), self.values.as_arc(), diff --git a/src/array/map/ffi.rs b/src/array/map/ffi.rs index 5607110ae48..33333596a01 100644 --- a/src/array/map/ffi.rs +++ b/src/array/map/ffi.rs @@ -58,6 +58,6 @@ impl FromFfi 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) } } diff --git a/src/array/map/mod.rs b/src/array/map/mod.rs index a8224051b41..5e8243feb7a 100644 --- a/src/array/map/mod.rs +++ b/src/array/map/mod.rs @@ -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, @@ -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) } } diff --git a/src/array/null.rs b/src/array/null.rs index a93cec49d42..cfd3a50b14d 100644 --- a/src/array/null.rs +++ b/src/array/null.rs @@ -44,12 +44,12 @@ impl NullArray { /// Returns a new empty [`NullArray`]. pub fn new_empty(data_type: DataType) -> Self { - Self::from_data(data_type, 0) + Self::new(data_type, 0) } /// Returns a new [`NullArray`]. pub fn new_null(data_type: DataType, length: usize) -> Self { - Self::from_data(data_type, length) + Self::new(data_type, length) } } @@ -124,6 +124,6 @@ unsafe impl ToFfi for NullArray { impl FromFfi for NullArray { unsafe fn try_from_ffi(array: A) -> Result { let data_type = array.data_type().clone(); - Ok(Self::from_data(data_type, array.array().len())) + Self::try_new(data_type, array.array().len()) } } diff --git a/src/array/primitive/ffi.rs b/src/array/primitive/ffi.rs index f5b4e5438ec..f1a73692279 100644 --- a/src/array/primitive/ffi.rs +++ b/src/array/primitive/ffi.rs @@ -55,6 +55,6 @@ impl FromFfi for PrimitiveArray { let validity = unsafe { array.validity() }?; let values = unsafe { array.buffer::(1) }?; - Ok(Self::from_data(data_type, values, validity)) + Self::try_new(data_type, values, validity) } } diff --git a/src/array/primitive/from_natural.rs b/src/array/primitive/from_natural.rs index cec159171d4..3d259f90604 100644 --- a/src/array/primitive/from_natural.rs +++ b/src/array/primitive/from_natural.rs @@ -21,14 +21,14 @@ impl PrimitiveArray { /// # Implementation /// This does not assume that the iterator has a known length. pub fn from_values>(iter: I) -> Self { - Self::from_data(T::PRIMITIVE.into(), Vec::::from_iter(iter).into(), None) + Self::new(T::PRIMITIVE.into(), Vec::::from_iter(iter).into(), None) } /// Creates a (non-null) [`PrimitiveArray`] from a slice of values. /// # Implementation /// This is essentially a memcopy pub fn from_slice>(slice: P) -> Self { - Self::from_data( + Self::new( T::PRIMITIVE.into(), Vec::::from(slice.as_ref()).into(), None, @@ -38,7 +38,7 @@ impl PrimitiveArray { /// Creates a (non-null) [`PrimitiveArray`] from a vector of values. /// This does not have memcopy and is the fastest way to create a [`PrimitiveArray`]. pub fn from_vec(array: Vec) -> Self { - Self::from_data(T::PRIMITIVE.into(), array.into(), None) + Self::new(T::PRIMITIVE.into(), array.into(), None) } } diff --git a/src/array/primitive/mutable.rs b/src/array/primitive/mutable.rs index 67059b7db02..1b52c4eadee 100644 --- a/src/array/primitive/mutable.rs +++ b/src/array/primitive/mutable.rs @@ -28,7 +28,7 @@ impl From> for PrimitiveArray { None }; - PrimitiveArray::::from_data(other.data_type, other.values.into(), validity) + PrimitiveArray::::new(other.data_type, other.values.into(), validity) } } @@ -364,7 +364,7 @@ impl MutableArray for MutablePrimitiveArray { } fn as_box(&mut self) -> Box { - Box::new(PrimitiveArray::from_data( + Box::new(PrimitiveArray::new( self.data_type.clone(), std::mem::take(&mut self.values).into(), std::mem::take(&mut self.validity).map(|x| x.into()), @@ -372,7 +372,7 @@ impl MutableArray for MutablePrimitiveArray { } fn as_arc(&mut self) -> Arc { - Arc::new(PrimitiveArray::from_data( + Arc::new(PrimitiveArray::new( self.data_type.clone(), std::mem::take(&mut self.values).into(), std::mem::take(&mut self.validity).map(|x| x.into()), diff --git a/src/array/struct_/ffi.rs b/src/array/struct_/ffi.rs index b25b233e2e8..9f24db5253f 100644 --- a/src/array/struct_/ffi.rs +++ b/src/array/struct_/ffi.rs @@ -40,6 +40,6 @@ impl FromFfi for StructArray { }) .collect::>>>()?; - Ok(Self::from_data(data_type, values, validity)) + Self::try_new(data_type, values, validity) } } diff --git a/src/array/union/ffi.rs b/src/array/union/ffi.rs index 8dd15321ff1..f7c9292c605 100644 --- a/src/array/union/ffi.rs +++ b/src/array/union/ffi.rs @@ -55,6 +55,6 @@ impl FromFfi for UnionArray { types = types.slice(offset, length); }; - Ok(Self::from_data(data_type, types, fields, offsets)) + Self::try_new(data_type, types, fields, offsets) } } diff --git a/src/array/union/mod.rs b/src/array/union/mod.rs index 351f88f56cb..47277bc9b37 100644 --- a/src/array/union/mod.rs +++ b/src/array/union/mod.rs @@ -144,7 +144,7 @@ impl UnionArray { // all from the same field let types = Buffer::new_zeroed(length); - Self::from_data(data_type, types, fields, offsets) + Self::new(data_type, types, fields, offsets) } else { panic!("Union struct must be created with the corresponding Union DataType") } diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index a2538dd58a0..81cf97d2243 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -132,7 +132,7 @@ impl Utf8Array { /// Returns a new [`Utf8Array`] whose all slots are null / `None`. #[inline] pub fn new_null(data_type: DataType, length: usize) -> Self { - Self::from_data( + Self::new( data_type, Buffer::new_zeroed(length + 1), Buffer::new(), @@ -286,33 +286,49 @@ impl Utf8Array { use Either::*; if let Some(bitmap) = self.validity { match bitmap.into_mut() { - Left(bitmap) => Left(Utf8Array::from_data( - self.data_type, - self.offsets, - self.values, - Some(bitmap), - )), + // Safety: invariants are preserved + Left(bitmap) => Left(unsafe { + Utf8Array::new_unchecked( + self.data_type, + self.offsets, + self.values, + Some(bitmap), + ) + }), Right(mutable_bitmap) => match (self.values.into_mut(), self.offsets.into_mut()) { (Left(immutable_values), Left(immutable_offsets)) => { - Left(Utf8Array::from_data( - self.data_type, - immutable_offsets, - immutable_values, - Some(mutable_bitmap.into()), - )) + // Safety: invariants are preserved + Left(unsafe { + Utf8Array::new_unchecked( + self.data_type, + immutable_offsets, + immutable_values, + Some(mutable_bitmap.into()), + ) + }) + } + (Left(immutable_values), Right(mutable_offsets)) => { + // Safety: invariants are preserved + Left(unsafe { + Utf8Array::new_unchecked( + self.data_type, + mutable_offsets.into(), + immutable_values, + Some(mutable_bitmap.into()), + ) + }) + } + (Right(mutable_values), Left(immutable_offsets)) => { + // Safety: invariants are preserved + Left(unsafe { + Utf8Array::new_unchecked( + self.data_type, + immutable_offsets, + mutable_values.into(), + Some(mutable_bitmap.into()), + ) + }) } - (Left(immutable_values), Right(mutable_offsets)) => Left(Utf8Array::from_data( - self.data_type, - mutable_offsets.into(), - immutable_values, - Some(mutable_bitmap.into()), - )), - (Right(mutable_values), Left(immutable_offsets)) => Left(Utf8Array::from_data( - self.data_type, - immutable_offsets, - mutable_values.into(), - Some(mutable_bitmap.into()), - )), (Right(mutable_values), Right(mutable_offsets)) => { Right(MutableUtf8Array::from_data( self.data_type, diff --git a/src/compute/arithmetics/decimal/add.rs b/src/compute/arithmetics/decimal/add.rs index 360dca818f6..f3b6a0b4a1a 100644 --- a/src/compute/arithmetics/decimal/add.rs +++ b/src/compute/arithmetics/decimal/add.rs @@ -225,7 +225,7 @@ pub fn adaptive_add( let validity = combine_validities(lhs.validity(), rhs.validity()); - Ok(PrimitiveArray::::from_data( + Ok(PrimitiveArray::::new( DataType::Decimal(res_p, res_s), values, validity, diff --git a/src/compute/arithmetics/decimal/div.rs b/src/compute/arithmetics/decimal/div.rs index 93ce6daca62..1085b1ab285 100644 --- a/src/compute/arithmetics/decimal/div.rs +++ b/src/compute/arithmetics/decimal/div.rs @@ -290,7 +290,7 @@ pub fn adaptive_div( let validity = combine_validities(lhs.validity(), rhs.validity()); - Ok(PrimitiveArray::::from_data( + Ok(PrimitiveArray::::new( DataType::Decimal(res_p, res_s), values, validity, diff --git a/src/compute/arithmetics/decimal/mul.rs b/src/compute/arithmetics/decimal/mul.rs index 8eb97a70bcd..01c505349ef 100644 --- a/src/compute/arithmetics/decimal/mul.rs +++ b/src/compute/arithmetics/decimal/mul.rs @@ -302,7 +302,7 @@ pub fn adaptive_mul( let validity = combine_validities(lhs.validity(), rhs.validity()); - Ok(PrimitiveArray::::from_data( + Ok(PrimitiveArray::::new( DataType::Decimal(res_p, res_s), values, validity, diff --git a/src/compute/arithmetics/decimal/sub.rs b/src/compute/arithmetics/decimal/sub.rs index 05a505c2e63..3c10eab87ce 100644 --- a/src/compute/arithmetics/decimal/sub.rs +++ b/src/compute/arithmetics/decimal/sub.rs @@ -225,7 +225,7 @@ pub fn adaptive_sub( let validity = combine_validities(lhs.validity(), rhs.validity()); - Ok(PrimitiveArray::::from_data( + Ok(PrimitiveArray::::new( DataType::Decimal(res_p, res_s), values, validity, diff --git a/src/compute/arity.rs b/src/compute/arity.rs index a7c359bf337..68142bcec23 100644 --- a/src/compute/arity.rs +++ b/src/compute/arity.rs @@ -29,7 +29,7 @@ where let values = array.values().iter().map(|v| op(*v)); let values = Buffer::from_trusted_len_iter(values); - PrimitiveArray::::from_data(data_type, values, array.validity().cloned()) + PrimitiveArray::::new(data_type, values, array.validity().cloned()) } /// Version of unary that checks for errors in the closure used to create the @@ -47,7 +47,7 @@ where let values = array.values().iter().map(|v| op(*v)); let values = Buffer::try_from_trusted_len_iter(values)?; - Ok(PrimitiveArray::::from_data( + Ok(PrimitiveArray::::new( data_type, values, array.validity().cloned(), @@ -77,7 +77,7 @@ where let values = Buffer::from_trusted_len_iter(values); ( - PrimitiveArray::::from_data(data_type, values, array.validity().cloned()), + PrimitiveArray::::new(data_type, values, array.validity().cloned()), mut_bitmap.into(), ) } @@ -117,7 +117,7 @@ where let bitmap: Bitmap = mut_bitmap.into(); let validity = combine_validities(array.validity(), Some(&bitmap)); - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } /// Applies a binary operations to two primitive arrays. This is the fastest @@ -156,7 +156,7 @@ where .map(|(l, r)| op(*l, *r)); let values = Buffer::from_trusted_len_iter(values); - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } /// Version of binary that checks for errors in the closure used to create the @@ -184,7 +184,7 @@ where let values = Buffer::try_from_trusted_len_iter(values)?; - Ok(PrimitiveArray::::from_data(data_type, values, validity)) + Ok(PrimitiveArray::::new(data_type, values, validity)) } /// Version of binary that returns an array and bitmap. Used when working with @@ -215,7 +215,7 @@ where let values = Buffer::from_trusted_len_iter(values); ( - PrimitiveArray::::from_data(data_type, values, validity), + PrimitiveArray::::new(data_type, values, validity), mut_bitmap.into(), ) } @@ -264,5 +264,5 @@ where // as Null let validity = combine_validities(validity.as_ref(), Some(&bitmap)); - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } diff --git a/src/compute/boolean.rs b/src/compute/boolean.rs index 1d31a508c53..b4258a8a15d 100644 --- a/src/compute/boolean.rs +++ b/src/compute/boolean.rs @@ -25,7 +25,7 @@ where let values = op(left_buffer, right_buffer); - Ok(BooleanArray::from_data(DataType::Boolean, values, validity)) + Ok(BooleanArray::new(DataType::Boolean, values, validity)) } /// Performs `AND` operation on two arrays. If either left or right value is null then the @@ -85,7 +85,7 @@ pub fn or(lhs: &BooleanArray, rhs: &BooleanArray) -> Result { pub fn not(array: &BooleanArray) -> BooleanArray { let values = !array.values(); let validity = array.validity().cloned(); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } /// Returns a non-null [BooleanArray] with whether each value of the array is null. @@ -109,7 +109,7 @@ pub fn is_null(input: &dyn Array) -> BooleanArray { Some(buffer) => !buffer, }; - BooleanArray::from_data(DataType::Boolean, values, None) + BooleanArray::new(DataType::Boolean, values, None) } /// Returns a non-null [BooleanArray] with whether each value of the array is not null. @@ -132,7 +132,7 @@ pub fn is_not_null(input: &dyn Array) -> BooleanArray { } Some(buffer) => buffer.clone(), }; - BooleanArray::from_data(DataType::Boolean, values, None) + BooleanArray::new(DataType::Boolean, values, None) } /// Performs `AND` operation on an array and a scalar value. If either left or right value @@ -154,7 +154,7 @@ pub fn and_scalar(array: &BooleanArray, scalar: &BooleanScalar) -> BooleanArray Some(true) => array.clone(), Some(false) => { let values = Bitmap::new_zeroed(array.len()); - BooleanArray::from_data(DataType::Boolean, values, array.validity().cloned()) + BooleanArray::new(DataType::Boolean, values, array.validity().cloned()) } None => BooleanArray::new_null(DataType::Boolean, array.len()), } @@ -179,7 +179,7 @@ pub fn or_scalar(array: &BooleanArray, scalar: &BooleanScalar) -> BooleanArray { Some(true) => { let mut values = MutableBitmap::new(); values.extend_constant(array.len(), true); - BooleanArray::from_data(DataType::Boolean, values.into(), array.validity().cloned()) + BooleanArray::new(DataType::Boolean, values.into(), array.validity().cloned()) } Some(false) => array.clone(), None => BooleanArray::new_null(DataType::Boolean, array.len()), diff --git a/src/compute/boolean_kleene.rs b/src/compute/boolean_kleene.rs index ec5d7e0db95..77093f9b424 100644 --- a/src/compute/boolean_kleene.rs +++ b/src/compute/boolean_kleene.rs @@ -90,7 +90,7 @@ pub fn or(lhs: &BooleanArray, rhs: &BooleanArray) -> Result { } (None, None) => None, }; - Ok(BooleanArray::from_data( + Ok(BooleanArray::new( DataType::Boolean, lhs_values | rhs_values, validity, @@ -179,7 +179,7 @@ pub fn and(lhs: &BooleanArray, rhs: &BooleanArray) -> Result { } (None, None) => None, }; - Ok(BooleanArray::from_data( + Ok(BooleanArray::new( DataType::Boolean, lhs_values & rhs_values, validity, @@ -205,7 +205,7 @@ pub fn or_scalar(array: &BooleanArray, scalar: &BooleanScalar) -> BooleanArray { Some(true) => { let mut values = MutableBitmap::new(); values.extend_constant(array.len(), true); - BooleanArray::from_data(DataType::Boolean, values.into(), None) + BooleanArray::new(DataType::Boolean, values.into(), None) } Some(false) => array.clone(), None => { @@ -214,7 +214,7 @@ pub fn or_scalar(array: &BooleanArray, scalar: &BooleanScalar) -> BooleanArray { Some(validity) => binary(values, validity, |value, validity| validity & value), None => unary(values, |value| value), }; - BooleanArray::from_data(DataType::Boolean, values.clone(), Some(validity)) + BooleanArray::new(DataType::Boolean, values.clone(), Some(validity)) } } } @@ -238,7 +238,7 @@ pub fn and_scalar(array: &BooleanArray, scalar: &BooleanScalar) -> BooleanArray Some(true) => array.clone(), Some(false) => { let values = Bitmap::new_zeroed(array.len()); - BooleanArray::from_data(DataType::Boolean, values, None) + BooleanArray::new(DataType::Boolean, values, None) } None => { let values = array.values(); @@ -246,7 +246,7 @@ pub fn and_scalar(array: &BooleanArray, scalar: &BooleanScalar) -> BooleanArray Some(validity) => binary(values, validity, |value, validity| validity & !value), None => unary(values, |value| !value), }; - BooleanArray::from_data(DataType::Boolean, array.values().clone(), Some(validity)) + BooleanArray::new(DataType::Boolean, array.values().clone(), Some(validity)) } } } diff --git a/src/compute/cast/binary_to.rs b/src/compute/cast/binary_to.rs index 538825f8965..faba71738dd 100644 --- a/src/compute/cast/binary_to.rs +++ b/src/compute/cast/binary_to.rs @@ -10,7 +10,7 @@ pub fn binary_to_large_binary(from: &BinaryArray, to_data_type: DataType) - let values = from.values().clone(); let offsets = from.offsets().iter().map(|x| *x as i64); let offsets = Buffer::from_trusted_len_iter(offsets); - BinaryArray::::from_data(to_data_type, offsets, values, from.validity().cloned()) + BinaryArray::::new(to_data_type, offsets, values, from.validity().cloned()) } /// Conversion of binary @@ -24,7 +24,7 @@ pub fn binary_large_to_binary( let offsets = from.offsets().iter().map(|x| *x as i32); let offsets = Buffer::from_trusted_len_iter(offsets); - Ok(BinaryArray::::from_data( + Ok(BinaryArray::::new( to_data_type, offsets, values, diff --git a/src/compute/cast/boolean_to.rs b/src/compute/cast/boolean_to.rs index 45005988df4..e8c3951dcb0 100644 --- a/src/compute/cast/boolean_to.rs +++ b/src/compute/cast/boolean_to.rs @@ -23,7 +23,7 @@ where .map(|x| if x { T::one() } else { T::default() }); let values = Buffer::::from_trusted_len_iter(iter); - PrimitiveArray::::from_data(T::PRIMITIVE.into(), values, from.validity().cloned()) + PrimitiveArray::::new(T::PRIMITIVE.into(), values, from.validity().cloned()) } /// Casts the [`BooleanArray`] to a [`Utf8Array`], casting trues to `"1"` and falses to `"0"` diff --git a/src/compute/cast/decimal_to.rs b/src/compute/cast/decimal_to.rs index 3434e2666e1..219d99cff1c 100644 --- a/src/compute/cast/decimal_to.rs +++ b/src/compute/cast/decimal_to.rs @@ -98,7 +98,7 @@ where .map(|x| (*x as f64 / div).as_()) .collect(); - PrimitiveArray::::from_data(T::PRIMITIVE.into(), values, from.validity().cloned()) + PrimitiveArray::::new(T::PRIMITIVE.into(), values, from.validity().cloned()) } pub(super) fn decimal_to_float_dyn(from: &dyn Array) -> Result> diff --git a/src/compute/cast/mod.rs b/src/compute/cast/mod.rs index 3e6adf5a30b..029b6a3cd9e 100644 --- a/src/compute/cast/mod.rs +++ b/src/compute/cast/mod.rs @@ -307,7 +307,7 @@ fn cast_list( )? .into(); - Ok(ListArray::::from_data( + Ok(ListArray::::new( to_type.clone(), array.offsets().clone(), new_values, @@ -323,7 +323,7 @@ fn cast_list_to_large_list(array: &ListArray, to_type: &DataType) -> ListAr .collect::>() .into(); - ListArray::::from_data( + ListArray::::new( to_type.clone(), offets, array.values().clone(), @@ -339,7 +339,7 @@ fn cast_large_to_list(array: &ListArray, to_type: &DataType) -> ListArray>() .into(); - ListArray::::from_data( + ListArray::::new( to_type.clone(), offsets, array.values().clone(), @@ -419,8 +419,7 @@ pub fn cast(array: &dyn Array, to_type: &DataType, options: CastOptions) -> Resu // create offsets, where if array.len() = 2, we have [0,1,2] let offsets = (0..=array.len() as i32).collect::>(); - let list_array = - ListArray::::from_data(to_type.clone(), offsets.into(), values, None); + let list_array = ListArray::::new(to_type.clone(), offsets.into(), values, None); Ok(Box::new(list_array)) } diff --git a/src/compute/cast/primitive_to.rs b/src/compute/cast/primitive_to.rs index b7a7a310c5a..cdd1317e364 100644 --- a/src/compute/cast/primitive_to.rs +++ b/src/compute/cast/primitive_to.rs @@ -66,7 +66,7 @@ pub fn primitive_to_boolean( let iter = from.values().iter().map(|v| *v != T::default()); let values = Bitmap::from_trusted_len_iter(iter); - BooleanArray::from_data(to_type, values, from.validity().cloned()) + BooleanArray::new(to_type, values, from.validity().cloned()) } pub(super) fn primitive_to_boolean_dyn( @@ -264,7 +264,7 @@ pub fn primitive_to_same_primitive( where T: NativeType, { - PrimitiveArray::::from_data( + PrimitiveArray::::new( to_type.clone(), from.values().clone(), from.validity().cloned(), diff --git a/src/compute/comparison/binary.rs b/src/compute/comparison/binary.rs index 5728a1b56dd..242c334d2ea 100644 --- a/src/compute/comparison/binary.rs +++ b/src/compute/comparison/binary.rs @@ -25,7 +25,7 @@ where .map(|(lhs, rhs)| op(lhs, rhs)); let values = Bitmap::from_trusted_len_iter(values); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } /// Evaluate `op(lhs, rhs)` for [`BinaryArray`] and scalar using @@ -40,7 +40,7 @@ where let values = lhs.values_iter().map(|lhs| op(lhs, rhs)); let values = Bitmap::from_trusted_len_iter(values); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } /// Perform `lhs == rhs` operation on [`BinaryArray`]. diff --git a/src/compute/comparison/boolean.rs b/src/compute/comparison/boolean.rs index 21269cde382..256f2f3f851 100644 --- a/src/compute/comparison/boolean.rs +++ b/src/compute/comparison/boolean.rs @@ -19,7 +19,7 @@ where let values = binary(lhs.values(), rhs.values(), op); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } /// Evaluate `op(left, right)` for [`BooleanArray`] and scalar using @@ -31,7 +31,7 @@ where let rhs = if rhs { !0 } else { 0 }; let values = unary(lhs.values(), |x| op(x, rhs)); - BooleanArray::from_data(DataType::Boolean, values, lhs.validity().cloned()) + BooleanArray::new(DataType::Boolean, values, lhs.validity().cloned()) } /// Perform `lhs == rhs` operation on two [`BooleanArray`]s. @@ -113,7 +113,7 @@ pub fn lt_scalar(lhs: &BooleanArray, rhs: bool) -> BooleanArray { if rhs { compare_op_scalar(lhs, rhs, |a, _| !a) } else { - BooleanArray::from_data( + BooleanArray::new( DataType::Boolean, Bitmap::new_zeroed(lhs.len()), lhs.validity().cloned(), @@ -147,7 +147,7 @@ pub fn gt(lhs: &BooleanArray, rhs: &BooleanArray) -> BooleanArray { /// Non-null values are greater than null values. pub fn gt_scalar(lhs: &BooleanArray, rhs: bool) -> BooleanArray { if rhs { - BooleanArray::from_data( + BooleanArray::new( DataType::Boolean, Bitmap::new_zeroed(lhs.len()), lhs.validity().cloned(), diff --git a/src/compute/comparison/mod.rs b/src/compute/comparison/mod.rs index 4c5aa710d4d..9ed47c16a79 100644 --- a/src/compute/comparison/mod.rs +++ b/src/compute/comparison/mod.rs @@ -510,18 +510,18 @@ fn finish_eq_validities( match (validity_lhs, validity_rhs) { (None, None) => output_without_validities, (Some(lhs), None) => compute::boolean::and( - &BooleanArray::from_data(DataType::Boolean, lhs, None), + &BooleanArray::new(DataType::Boolean, lhs, None), &output_without_validities, ) .unwrap(), (None, Some(rhs)) => compute::boolean::and( &output_without_validities, - &BooleanArray::from_data(DataType::Boolean, rhs, None), + &BooleanArray::new(DataType::Boolean, rhs, None), ) .unwrap(), (Some(lhs), Some(rhs)) => { - let lhs = BooleanArray::from_data(DataType::Boolean, lhs, None); - let rhs = BooleanArray::from_data(DataType::Boolean, rhs, None); + let lhs = BooleanArray::new(DataType::Boolean, lhs, None); + let rhs = BooleanArray::new(DataType::Boolean, rhs, None); let eq_validities = compute::comparison::boolean::eq(&lhs, &rhs); compute::boolean::and(&output_without_validities, &eq_validities).unwrap() } @@ -536,17 +536,17 @@ fn finish_neq_validities( (None, None) => output_without_validities, (Some(lhs), None) => { let lhs_negated = - compute::boolean::not(&BooleanArray::from_data(DataType::Boolean, lhs, None)); + compute::boolean::not(&BooleanArray::new(DataType::Boolean, lhs, None)); compute::boolean::or(&lhs_negated, &output_without_validities).unwrap() } (None, Some(rhs)) => { let rhs_negated = - compute::boolean::not(&BooleanArray::from_data(DataType::Boolean, rhs, None)); + compute::boolean::not(&BooleanArray::new(DataType::Boolean, rhs, None)); compute::boolean::or(&output_without_validities, &rhs_negated).unwrap() } (Some(lhs), Some(rhs)) => { - let lhs = BooleanArray::from_data(DataType::Boolean, lhs, None); - let rhs = BooleanArray::from_data(DataType::Boolean, rhs, None); + let lhs = BooleanArray::new(DataType::Boolean, lhs, None); + let rhs = BooleanArray::new(DataType::Boolean, rhs, None); let neq_validities = compute::comparison::boolean::neq(&lhs, &rhs); compute::boolean::or(&output_without_validities, &neq_validities).unwrap() } diff --git a/src/compute/comparison/primitive.rs b/src/compute/comparison/primitive.rs index d734d699720..d801bdc1d75 100644 --- a/src/compute/comparison/primitive.rs +++ b/src/compute/comparison/primitive.rs @@ -74,7 +74,7 @@ where let values = compare_values_op(lhs.values(), rhs.values(), op); - BooleanArray::from_data(DataType::Boolean, values.into(), validity) + BooleanArray::new(DataType::Boolean, values.into(), validity) } /// Evaluate `op(left, right)` for [`PrimitiveArray`] and scalar using @@ -88,7 +88,7 @@ where let values = compare_values_op_scalar(lhs.values(), rhs, op); - BooleanArray::from_data(DataType::Boolean, values.into(), validity) + BooleanArray::new(DataType::Boolean, values.into(), validity) } /// Perform `lhs == rhs` operation on two arrays. diff --git a/src/compute/comparison/utf8.rs b/src/compute/comparison/utf8.rs index cc396dbf800..c8a855a0860 100644 --- a/src/compute/comparison/utf8.rs +++ b/src/compute/comparison/utf8.rs @@ -24,7 +24,7 @@ where .map(|(lhs, rhs)| op(lhs, rhs)); let values = Bitmap::from_trusted_len_iter(values); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } /// Evaluate `op(lhs, rhs)` for [`Utf8Array`] and scalar using @@ -39,7 +39,7 @@ where let values = lhs.values_iter().map(|lhs| op(lhs, rhs)); let values = Bitmap::from_trusted_len_iter(values); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } /// Perform `lhs == rhs` operation on [`Utf8Array`]. diff --git a/src/compute/contains.rs b/src/compute/contains.rs index 7e7c07721a0..be01bcf6366 100644 --- a/src/compute/contains.rs +++ b/src/compute/contains.rs @@ -42,7 +42,7 @@ where }); let values = Bitmap::from_trusted_len_iter(values); - Ok(BooleanArray::from_data(DataType::Boolean, values, validity)) + Ok(BooleanArray::new(DataType::Boolean, values, validity)) } /// Checks if a [`GenericListArray`] contains a value in the [`Utf8Array`] @@ -76,7 +76,7 @@ where }); let values = Bitmap::from_trusted_len_iter(values); - Ok(BooleanArray::from_data(DataType::Boolean, values, validity)) + Ok(BooleanArray::new(DataType::Boolean, values, validity)) } /// Checks if a [`ListArray`] contains a value in the [`BinaryArray`] @@ -110,7 +110,7 @@ where }); let values = Bitmap::from_trusted_len_iter(values); - Ok(BooleanArray::from_data(DataType::Boolean, values, validity)) + Ok(BooleanArray::new(DataType::Boolean, values, validity)) } macro_rules! primitive { diff --git a/src/compute/filter.rs b/src/compute/filter.rs index 27ddf4fdee9..a327ad4b505 100644 --- a/src/compute/filter.rs +++ b/src/compute/filter.rs @@ -170,10 +170,10 @@ fn filter_nonnull_primitive( if let Some(validity) = array.validity() { let (values, validity) = null_filter_simd(array.values(), validity, mask); - PrimitiveArray::::from_data(array.data_type().clone(), values.into(), validity.into()) + PrimitiveArray::::new(array.data_type().clone(), values.into(), validity.into()) } else { let values = nonnull_filter_simd(array.values(), mask); - PrimitiveArray::::from_data(array.data_type().clone(), values.into(), None) + PrimitiveArray::::new(array.data_type().clone(), values.into(), None) } } @@ -260,7 +260,7 @@ pub fn filter(array: &dyn Array, filter: &BooleanArray) -> Result if let Some(validities) = filter.validity() { let values = filter.values(); let new_values = values & validities; - let filter = BooleanArray::from_data(DataType::Boolean, new_values, None); + let filter = BooleanArray::new(DataType::Boolean, new_values, None); return crate::compute::filter::filter(array, &filter); } diff --git a/src/compute/hash.rs b/src/compute/hash.rs index eb61872caef..f21d0c82cac 100644 --- a/src/compute/hash.rs +++ b/src/compute/hash.rs @@ -38,7 +38,7 @@ pub fn hash_boolean(array: &BooleanArray) -> PrimitiveArray { let iter = array.values_iter().map(|x| u8::get_hash(&x, &state)); let values = Buffer::from_trusted_len_iter(iter); - PrimitiveArray::::from_data(DataType::UInt64, values, array.validity().cloned()) + PrimitiveArray::::new(DataType::UInt64, values, array.validity().cloned()) } #[multiversion] @@ -51,7 +51,7 @@ pub fn hash_utf8(array: &Utf8Array) -> PrimitiveArray { .values_iter() .map(|x| <[u8]>::get_hash(&x.as_bytes(), &state)); let values = Buffer::from_trusted_len_iter(iter); - PrimitiveArray::::from_data(DataType::UInt64, values, array.validity().cloned()) + PrimitiveArray::::new(DataType::UInt64, values, array.validity().cloned()) } /// Element-wise hash of a [`BinaryArray`]. Validity is preserved. @@ -59,7 +59,7 @@ pub fn hash_binary(array: &BinaryArray) -> PrimitiveArray { let state = new_state!(); let iter = array.values_iter().map(|x| <[u8]>::get_hash(&x, &state)); let values = Buffer::from_trusted_len_iter(iter); - PrimitiveArray::::from_data(DataType::UInt64, values, array.validity().cloned()) + PrimitiveArray::::new(DataType::UInt64, values, array.validity().cloned()) } macro_rules! with_match_primitive_type {( diff --git a/src/compute/length.rs b/src/compute/length.rs index fa9434458eb..459215c7e32 100644 --- a/src/compute/length.rs +++ b/src/compute/length.rs @@ -43,7 +43,7 @@ where DataType::Int32 }; - PrimitiveArray::::from_data(data_type, values, array.validity().cloned()) + PrimitiveArray::::new(data_type, values, array.validity().cloned()) } /// Returns an array of integers with the number of bytes on each string of the array. diff --git a/src/compute/like.rs b/src/compute/like.rs index 3c262585672..4f2b2d6eebe 100644 --- a/src/compute/like.rs +++ b/src/compute/like.rs @@ -60,7 +60,7 @@ fn a_like_utf8 bool>( } }))?; - Ok(BooleanArray::from_data(DataType::Boolean, values, validity)) + Ok(BooleanArray::new(DataType::Boolean, values, validity)) } /// Returns `lhs LIKE rhs` operation on two [`Utf8Array`]. @@ -126,7 +126,7 @@ fn a_like_utf8_scalar bool>( })?; Bitmap::from_trusted_len_iter(lhs.values_iter().map(|x| op(re.is_match(x)))) }; - Ok(BooleanArray::from_data( + Ok(BooleanArray::new( DataType::Boolean, values, validity.cloned(), @@ -208,7 +208,7 @@ fn a_like_binary bool>( } }))?; - Ok(BooleanArray::from_data(DataType::Boolean, values, validity)) + Ok(BooleanArray::new(DataType::Boolean, values, validity)) } /// Returns `lhs LIKE rhs` operation on two [`BinaryArray`]. @@ -281,7 +281,7 @@ fn a_like_binary_scalar bool>( })?; Bitmap::from_trusted_len_iter(lhs.values_iter().map(|x| op(re.is_match(x)))) }; - Ok(BooleanArray::from_data( + Ok(BooleanArray::new( DataType::Boolean, values, validity.cloned(), diff --git a/src/compute/nullif.rs b/src/compute/nullif.rs index 88053ef4ad0..b93e518da7f 100644 --- a/src/compute/nullif.rs +++ b/src/compute/nullif.rs @@ -42,7 +42,7 @@ where let validity = combine_validities(lhs.validity(), equal.as_ref()); - PrimitiveArray::::from_data(lhs.data_type().clone(), lhs.values().clone(), validity) + PrimitiveArray::::new(lhs.data_type().clone(), lhs.values().clone(), validity) } /// Returns a [`PrimitiveArray`] whose validity is null iff `lhs == rhs` or `lhs` is null. @@ -75,7 +75,7 @@ where let validity = combine_validities(lhs.validity(), equal.as_ref()); - PrimitiveArray::::from_data(lhs.data_type().clone(), lhs.values().clone(), validity) + PrimitiveArray::::new(lhs.data_type().clone(), lhs.values().clone(), validity) } /// Returns an [`Array`] with the same type as `lhs` and whose validity diff --git a/src/compute/regex_match.rs b/src/compute/regex_match.rs index 5866a4310d9..75fc8730edf 100644 --- a/src/compute/regex_match.rs +++ b/src/compute/regex_match.rs @@ -46,11 +46,7 @@ pub fn regex_match(values: &Utf8Array, regex: &Utf8Array) -> Re }); let new_values = Bitmap::try_from_trusted_len_iter(iterator)?; - Ok(BooleanArray::from_data( - DataType::Boolean, - new_values, - validity, - )) + Ok(BooleanArray::new(DataType::Boolean, new_values, validity)) } /// Regex matches @@ -83,5 +79,5 @@ fn unary_utf8_boolean bool>( op(value.unwrap()) }); let values = Bitmap::from_trusted_len_iter(iterator); - BooleanArray::from_data(DataType::Boolean, values, validity) + BooleanArray::new(DataType::Boolean, values, validity) } diff --git a/src/compute/sort/boolean.rs b/src/compute/sort/boolean.rs index 525206bc833..d70181eb39e 100644 --- a/src/compute/sort/boolean.rs +++ b/src/compute/sort/boolean.rs @@ -49,5 +49,5 @@ pub fn sort_boolean( } let data_type = I::PRIMITIVE.into(); - PrimitiveArray::::from_data(data_type, values.into(), None) + PrimitiveArray::::new(data_type, values.into(), None) } diff --git a/src/compute/sort/common.rs b/src/compute/sort/common.rs index d23838b8fc8..dea456c72a7 100644 --- a/src/compute/sort/common.rs +++ b/src/compute/sort/common.rs @@ -162,5 +162,5 @@ where }; let data_type = I::PRIMITIVE.into(); - PrimitiveArray::::from_data(data_type, indices.into(), None) + PrimitiveArray::::new(data_type, indices.into(), None) } diff --git a/src/compute/sort/lex_sort.rs b/src/compute/sort/lex_sort.rs index 695269c92d2..bcf0f650b52 100644 --- a/src/compute/sort/lex_sort.rs +++ b/src/compute/sort/lex_sort.rs @@ -180,9 +180,5 @@ pub fn lexsort_to_indices( } let data_type = I::PRIMITIVE.into(); - Ok(PrimitiveArray::::from_data( - data_type, - values.into(), - None, - )) + Ok(PrimitiveArray::::new(data_type, values.into(), None)) } diff --git a/src/compute/sort/mod.rs b/src/compute/sort/mod.rs index 767cde4cf32..7a85949402c 100644 --- a/src/compute/sort/mod.rs +++ b/src/compute/sort/mod.rs @@ -358,7 +358,7 @@ where values.truncate(limit.unwrap_or(values.len())); let data_type = I::PRIMITIVE.into(); - PrimitiveArray::::from_data(data_type, values.into(), None) + PrimitiveArray::::new(data_type, values.into(), None) } /// Compare two `Array`s based on the ordering defined in [ord](crate::array::ord). diff --git a/src/compute/sort/primitive/sort.rs b/src/compute/sort/primitive/sort.rs index cd85c5ba67b..a496edcf9c1 100644 --- a/src/compute/sort/primitive/sort.rs +++ b/src/compute/sort/primitive/sort.rs @@ -158,7 +158,7 @@ where (buffer.into(), None) }; - PrimitiveArray::::from_data(array.data_type().clone(), buffer, validity) + PrimitiveArray::::new(array.data_type().clone(), buffer, validity) } #[cfg(test)] diff --git a/src/compute/substring.rs b/src/compute/substring.rs index 2502eb3d9ba..d51ec605ce7 100644 --- a/src/compute/substring.rs +++ b/src/compute/substring.rs @@ -108,7 +108,7 @@ fn binary_substring( new_values.extend_from_slice(&values[start..start + length]); }); - BinaryArray::::from_data( + BinaryArray::::new( array.data_type().clone(), new_offsets.into(), new_values.into(), diff --git a/src/compute/take/binary.rs b/src/compute/take/binary.rs index 4bfb46abeda..0651b6bba13 100644 --- a/src/compute/take/binary.rs +++ b/src/compute/take/binary.rs @@ -37,5 +37,5 @@ pub fn take( (false, true) => take_indices_validity(values.offsets(), values.values(), indices), (true, true) => take_values_indices_validity(values, indices), }; - BinaryArray::::from_data(data_type, offsets, values, validity) + BinaryArray::::new(data_type, offsets, values, validity) } diff --git a/src/compute/take/boolean.rs b/src/compute/take/boolean.rs index a676e652c92..76ef8c67b32 100644 --- a/src/compute/take/boolean.rs +++ b/src/compute/take/boolean.rs @@ -97,7 +97,7 @@ pub fn take(values: &BooleanArray, indices: &PrimitiveArray) -> Boo (true, true) => take_values_indices_validity(values, indices), }; - BooleanArray::from_data(data_type, values, validity) + BooleanArray::new(data_type, values, validity) } #[cfg(test)] diff --git a/src/compute/take/mod.rs b/src/compute/take/mod.rs index 3d71e098d0a..b9ae790d0fd 100644 --- a/src/compute/take/mod.rs +++ b/src/compute/take/mod.rs @@ -44,7 +44,7 @@ pub fn take(values: &dyn Array, indices: &PrimitiveArray) -> Result use crate::datatypes::PhysicalType::*; match values.data_type().to_physical_type() { - Null => Ok(Box::new(NullArray::from_data( + Null => Ok(Box::new(NullArray::new( values.data_type().clone(), indices.len(), ))), diff --git a/src/compute/take/primitive.rs b/src/compute/take/primitive.rs index 70b358a5582..bd033680b63 100644 --- a/src/compute/take/primitive.rs +++ b/src/compute/take/primitive.rs @@ -111,5 +111,5 @@ pub fn take( (true, true) => take_values_indices_validity::(values, indices), }; - PrimitiveArray::::from_data(values.data_type().clone(), buffer, validity) + PrimitiveArray::::new(values.data_type().clone(), buffer, validity) } diff --git a/src/compute/take/structure.rs b/src/compute/take/structure.rs index 04e7f460e6c..2b94e8e43ab 100644 --- a/src/compute/take/structure.rs +++ b/src/compute/take/structure.rs @@ -60,7 +60,7 @@ pub fn take(array: &StructArray, indices: &PrimitiveArray) -> Resul .map(|a| super::take(a.as_ref(), indices).map(|x| x.into())) .collect::>()?; let validity = take_validity(array.validity(), indices)?; - Ok(StructArray::from_data( + Ok(StructArray::new( array.data_type().clone(), values, validity, diff --git a/src/io/avro/read/nested.rs b/src/io/avro/read/nested.rs index cf588899921..9a6992959d1 100644 --- a/src/io/avro/read/nested.rs +++ b/src/io/avro/read/nested.rs @@ -80,7 +80,7 @@ impl MutableArray for DynMutableListArray { } fn as_box(&mut self) -> Box { - Box::new(ListArray::from_data( + Box::new(ListArray::new( self.data_type.clone(), std::mem::take(&mut self.offsets).into(), self.values.as_arc(), @@ -89,7 +89,7 @@ impl MutableArray for DynMutableListArray { } fn as_arc(&mut self) -> Arc { - Arc::new(ListArray::from_data( + Arc::new(ListArray::new( self.data_type.clone(), std::mem::take(&mut self.offsets).into(), self.values.as_arc(), @@ -246,7 +246,7 @@ impl MutableArray for DynMutableStructArray { fn as_box(&mut self) -> Box { let values = self.values.iter_mut().map(|x| x.as_arc()).collect(); - Box::new(StructArray::from_data( + Box::new(StructArray::new( self.data_type.clone(), values, std::mem::take(&mut self.validity).map(|x| x.into()), @@ -256,7 +256,7 @@ impl MutableArray for DynMutableStructArray { fn as_arc(&mut self) -> Arc { let values = self.values.iter_mut().map(|x| x.as_arc()).collect(); - Arc::new(StructArray::from_data( + Arc::new(StructArray::new( self.data_type.clone(), values, std::mem::take(&mut self.validity).map(|x| x.into()), diff --git a/src/io/ipc/read/array/binary.rs b/src/io/ipc/read/array/binary.rs index f19069fd351..c485b617b8b 100644 --- a/src/io/ipc/read/array/binary.rs +++ b/src/io/ipc/read/array/binary.rs @@ -55,9 +55,7 @@ pub fn read_binary( compression, )?; - Ok(BinaryArray::::from_data( - data_type, offsets, values, validity, - )) + BinaryArray::::try_new(data_type, offsets, values, validity) } pub fn skip_binary( diff --git a/src/io/ipc/read/array/boolean.rs b/src/io/ipc/read/array/boolean.rs index 33c49694dad..feaebef38ed 100644 --- a/src/io/ipc/read/array/boolean.rs +++ b/src/io/ipc/read/array/boolean.rs @@ -42,7 +42,7 @@ pub fn read_boolean( is_little_endian, compression, )?; - Ok(BooleanArray::from_data(data_type, values, validity)) + BooleanArray::try_new(data_type, values, validity) } pub fn skip_boolean( diff --git a/src/io/ipc/read/array/fixed_size_binary.rs b/src/io/ipc/read/array/fixed_size_binary.rs index 0d5a84c65c7..91feef45f43 100644 --- a/src/io/ipc/read/array/fixed_size_binary.rs +++ b/src/io/ipc/read/array/fixed_size_binary.rs @@ -43,7 +43,7 @@ pub fn read_fixed_size_binary( compression, )?; - Ok(FixedSizeBinaryArray::from_data(data_type, values, validity)) + FixedSizeBinaryArray::try_new(data_type, values, validity) } pub fn skip_fixed_size_binary( diff --git a/src/io/ipc/read/array/fixed_size_list.rs b/src/io/ipc/read/array/fixed_size_list.rs index 0247b1e6ade..a3475319f6a 100644 --- a/src/io/ipc/read/array/fixed_size_list.rs +++ b/src/io/ipc/read/array/fixed_size_list.rs @@ -54,7 +54,7 @@ pub fn read_fixed_size_list( compression, version, )?; - Ok(FixedSizeListArray::from_data(data_type, values, validity)) + FixedSizeListArray::try_new(data_type, values, validity) } pub fn skip_fixed_size_list( diff --git a/src/io/ipc/read/array/list.rs b/src/io/ipc/read/array/list.rs index 46d2fdc5768..bebdb812ea0 100644 --- a/src/io/ipc/read/array/list.rs +++ b/src/io/ipc/read/array/list.rs @@ -70,7 +70,7 @@ where compression, version, )?; - Ok(ListArray::from_data(data_type, offsets, values, validity)) + ListArray::try_new(data_type, offsets, values, validity) } pub fn skip_list( diff --git a/src/io/ipc/read/array/map.rs b/src/io/ipc/read/array/map.rs index c22394d0fb5..5c9d892e9b9 100644 --- a/src/io/ipc/read/array/map.rs +++ b/src/io/ipc/read/array/map.rs @@ -66,7 +66,7 @@ pub fn read_map( compression, version, )?; - Ok(MapArray::from_data(data_type, offsets, field, validity)) + MapArray::try_new(data_type, offsets, field, validity) } pub fn skip_map( diff --git a/src/io/ipc/read/array/null.rs b/src/io/ipc/read/array/null.rs index 9ff7da6f775..013c472468a 100644 --- a/src/io/ipc/read/array/null.rs +++ b/src/io/ipc/read/array/null.rs @@ -16,10 +16,7 @@ pub fn read_null(field_nodes: &mut VecDeque, data_type: DataType) -> Resul )) })?; - Ok(NullArray::from_data( - data_type, - field_node.length() as usize, - )) + NullArray::try_new(data_type, field_node.length() as usize) } pub fn skip_null(field_nodes: &mut VecDeque) -> Result<()> { diff --git a/src/io/ipc/read/array/primitive.rs b/src/io/ipc/read/array/primitive.rs index a80905d3859..d6ceaefc410 100644 --- a/src/io/ipc/read/array/primitive.rs +++ b/src/io/ipc/read/array/primitive.rs @@ -44,7 +44,7 @@ where is_little_endian, compression, )?; - Ok(PrimitiveArray::::from_data(data_type, values, validity)) + PrimitiveArray::::try_new(data_type, values, validity) } pub fn skip_primitive( diff --git a/src/io/ipc/read/array/struct_.rs b/src/io/ipc/read/array/struct_.rs index 6594b331008..054c3f7d350 100644 --- a/src/io/ipc/read/array/struct_.rs +++ b/src/io/ipc/read/array/struct_.rs @@ -61,7 +61,7 @@ pub fn read_struct( }) .collect::>>()?; - Ok(StructArray::from_data(data_type, values, validity)) + StructArray::try_new(data_type, values, validity) } pub fn skip_struct( diff --git a/src/io/ipc/read/array/union.rs b/src/io/ipc/read/array/union.rs index b23f3ec9a7a..a1c999681a2 100644 --- a/src/io/ipc/read/array/union.rs +++ b/src/io/ipc/read/array/union.rs @@ -85,7 +85,7 @@ pub fn read_union( }) .collect::>>()?; - Ok(UnionArray::from_data(data_type, types, fields, offsets)) + UnionArray::try_new(data_type, types, fields, offsets) } pub fn skip_union( diff --git a/src/io/ipc/read/array/utf8.rs b/src/io/ipc/read/array/utf8.rs index 3d9a6b4e641..2e0a023eda5 100644 --- a/src/io/ipc/read/array/utf8.rs +++ b/src/io/ipc/read/array/utf8.rs @@ -55,9 +55,7 @@ pub fn read_utf8( compression, )?; - Ok(Utf8Array::::from_data( - data_type, offsets, values, validity, - )) + Utf8Array::::try_new(data_type, offsets, values, validity) } pub fn skip_utf8( diff --git a/src/io/json/read/deserialize.rs b/src/io/json/read/deserialize.rs index 7f5844ab1a3..ee8068d0819 100644 --- a/src/io/json/read/deserialize.rs +++ b/src/io/json/read/deserialize.rs @@ -135,7 +135,7 @@ fn deserialize_list>(rows: &[A], data_type: DataType let values = _deserialize(&inner, child.clone()); - ListArray::::from_data(data_type, offsets.into(), values, validity.into()) + ListArray::::new(data_type, offsets.into(), values, validity.into()) } fn deserialize_struct>(rows: &[A], data_type: DataType) -> StructArray { @@ -166,7 +166,7 @@ fn deserialize_struct>(rows: &[A], data_type: DataType) -> Stru .map(|(_, (data_type, values))| _deserialize(&values, data_type.clone())) .collect::>(); - StructArray::from_data(data_type, values, None) + StructArray::new(data_type, values, None) } fn deserialize_dictionary>( @@ -204,7 +204,7 @@ fn deserialize_dictionary>( pub(crate) fn _deserialize>(rows: &[A], data_type: DataType) -> Arc { match &data_type { - DataType::Null => Arc::new(NullArray::from_data(data_type, rows.len())), + DataType::Null => Arc::new(NullArray::new(data_type, rows.len())), DataType::Boolean => Arc::new(deserialize_boolean(rows)), DataType::Int8 => Arc::new(deserialize_int::(rows, data_type)), DataType::Int16 => Arc::new(deserialize_int::(rows, data_type)), diff --git a/src/io/json_integration/read/array.rs b/src/io/json_integration/read/array.rs index b73223b7488..f15c0a4de31 100644 --- a/src/io/json_integration/read/array.rs +++ b/src/io/json_integration/read/array.rs @@ -90,7 +90,7 @@ fn to_primitive_days_ms( .iter() .map(to_days_ms) .collect(); - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } fn to_primitive_months_days_ns( @@ -105,7 +105,7 @@ fn to_primitive_months_days_ns( .iter() .map(to_months_days_ns) .collect(); - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } fn to_decimal(json_col: &ArrowJsonColumn, data_type: DataType) -> PrimitiveArray { @@ -123,7 +123,7 @@ fn to_decimal(json_col: &ArrowJsonColumn, data_type: DataType) -> PrimitiveArray }) .collect(); - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } fn to_primitive( @@ -159,7 +159,7 @@ fn to_primitive( .collect() }; - PrimitiveArray::::from_data(data_type, values, validity) + PrimitiveArray::::new(data_type, values, validity) } fn to_binary(json_col: &ArrowJsonColumn, data_type: DataType) -> Arc { @@ -172,7 +172,7 @@ fn to_binary(json_col: &ArrowJsonColumn, data_type: DataType) -> Arc< .iter() .flat_map(|value| value.as_str().map(|x| hex::decode(x).unwrap()).unwrap()) .collect(); - Arc::new(BinaryArray::from_data(data_type, offsets, values, validity)) + Arc::new(BinaryArray::new(data_type, offsets, values, validity)) } fn to_utf8(json_col: &ArrowJsonColumn, data_type: DataType) -> Arc { @@ -185,7 +185,7 @@ fn to_utf8(json_col: &ArrowJsonColumn, data_type: DataType) -> Arc( @@ -205,7 +205,7 @@ fn to_list( dictionaries, )?; let offsets = to_offsets::(json_col.offset.as_ref()); - Ok(Arc::new(ListArray::::from_data( + Ok(Arc::new(ListArray::::new( data_type, offsets, values, validity, ))) } @@ -227,9 +227,7 @@ fn to_map( dictionaries, )?; let offsets = to_offsets::(json_col.offset.as_ref()); - Ok(Arc::new(MapArray::from_data( - data_type, offsets, field, validity, - ))) + Ok(Arc::new(MapArray::new(data_type, offsets, field, validity))) } fn to_dictionary( @@ -266,7 +264,7 @@ pub fn to_array( ) -> Result> { use PhysicalType::*; match data_type.to_physical_type() { - Null => Ok(Arc::new(NullArray::from_data(data_type, json_col.count))), + Null => Ok(Arc::new(NullArray::new(data_type, json_col.count))), Boolean => { let validity = to_validity(&json_col.validity); let values = json_col @@ -276,9 +274,7 @@ pub fn to_array( .iter() .map(|value| value.as_bool().unwrap()) .collect::(); - Ok(Arc::new(BooleanArray::from_data( - data_type, values, validity, - ))) + Ok(Arc::new(BooleanArray::new(data_type, values, validity))) } Primitive(PrimitiveType::Int8) => Ok(Arc::new(to_primitive::(json_col, data_type))), Primitive(PrimitiveType::Int16) => Ok(Arc::new(to_primitive::(json_col, data_type))), @@ -309,7 +305,7 @@ pub fn to_array( .iter() .flat_map(|value| value.as_str().map(|x| hex::decode(x).unwrap()).unwrap()) .collect(); - Ok(Arc::new(FixedSizeBinaryArray::from_data( + Ok(Arc::new(FixedSizeBinaryArray::new( data_type, values, validity, ))) } @@ -328,7 +324,7 @@ pub fn to_array( dictionaries, )?; - Ok(Arc::new(FixedSizeListArray::from_data( + Ok(Arc::new(FixedSizeListArray::new( data_type, values, validity, ))) } @@ -346,7 +342,7 @@ pub fn to_array( }) .collect::>>()?; - let array = StructArray::from_data(data_type, values, validity); + let array = StructArray::new(data_type, values, validity); Ok(Arc::new(array)) } Dictionary(key_type) => { @@ -400,7 +396,7 @@ pub fn to_array( }) .unwrap_or_default(); - let array = UnionArray::from_data(data_type, types, fields, offsets); + let array = UnionArray::new(data_type, types, fields, offsets); Ok(Arc::new(array)) } Map => to_map(json_col, data_type, field, dictionaries), diff --git a/src/io/parquet/read/deserialize/boolean/basic.rs b/src/io/parquet/read/deserialize/boolean/basic.rs index ced615b6101..c646c879ef4 100644 --- a/src/io/parquet/read/deserialize/boolean/basic.rs +++ b/src/io/parquet/read/deserialize/boolean/basic.rs @@ -126,7 +126,7 @@ impl<'a> Decoder<'a, bool, MutableBitmap> for BooleanDecoder { } fn finish(data_type: &DataType, values: MutableBitmap, validity: MutableBitmap) -> BooleanArray { - BooleanArray::from_data(data_type.clone(), values.into(), validity.into()) + BooleanArray::new(data_type.clone(), values.into(), validity.into()) } /// An iterator adapter over [`DataPages`] assumed to be encoded as boolean arrays diff --git a/src/io/parquet/read/deserialize/boolean/nested.rs b/src/io/parquet/read/deserialize/boolean/nested.rs index 2010e3633f6..fbda4644ce0 100644 --- a/src/io/parquet/read/deserialize/boolean/nested.rs +++ b/src/io/parquet/read/deserialize/boolean/nested.rs @@ -139,7 +139,7 @@ impl ArrayIterator { } fn finish(data_type: &DataType, values: MutableBitmap, validity: MutableBitmap) -> BooleanArray { - BooleanArray::from_data(data_type.clone(), values.into(), validity.into()) + BooleanArray::new(data_type.clone(), values.into(), validity.into()) } impl Iterator for ArrayIterator { diff --git a/src/io/parquet/read/deserialize/fixed_size_binary/basic.rs b/src/io/parquet/read/deserialize/fixed_size_binary/basic.rs index 0aaa08bdf99..a0c612626ea 100644 --- a/src/io/parquet/read/deserialize/fixed_size_binary/basic.rs +++ b/src/io/parquet/read/deserialize/fixed_size_binary/basic.rs @@ -204,7 +204,7 @@ fn finish( values: FixedSizeBinary, validity: MutableBitmap, ) -> FixedSizeBinaryArray { - FixedSizeBinaryArray::from_data(data_type.clone(), values.values.into(), validity.into()) + FixedSizeBinaryArray::new(data_type.clone(), values.values.into(), validity.into()) } pub struct Iter { diff --git a/src/io/parquet/read/deserialize/mod.rs b/src/io/parquet/read/deserialize/mod.rs index a6a2b48dc15..324cb906bc7 100644 --- a/src/io/parquet/read/deserialize/mod.rs +++ b/src/io/parquet/read/deserialize/mod.rs @@ -45,7 +45,7 @@ fn create_list( let (offsets, validity) = nested.nested.pop().unwrap().inner(); let offsets = offsets.iter().map(|x| *x as i32).collect::>(); - Arc::new(ListArray::::from_data( + Arc::new(ListArray::::new( data_type, offsets.into(), values, @@ -55,9 +55,7 @@ fn create_list( DataType::LargeList(_) => { let (offsets, validity) = nested.nested.pop().unwrap().inner(); - Arc::new(ListArray::::from_data( - data_type, offsets, values, validity, - )) + Arc::new(ListArray::::new(data_type, offsets, values, validity)) } _ => { return Err(ArrowError::NotYetImplemented(format!( diff --git a/src/io/parquet/read/deserialize/null.rs b/src/io/parquet/read/deserialize/null.rs index 08382ca6be1..363663c8ec1 100644 --- a/src/io/parquet/read/deserialize/null.rs +++ b/src/io/parquet/read/deserialize/null.rs @@ -22,12 +22,12 @@ where let remainder = chunk_size % len; let i_data_type = data_type.clone(); let complete = (0..complete_chunks).map(move |_| { - Ok(Arc::new(NullArray::from_data(i_data_type.clone(), chunk_size)) as Arc) + Ok(Arc::new(NullArray::new(i_data_type.clone(), chunk_size)) as Arc) }); if len % chunk_size == 0 { Box::new(complete) } else { - let array = NullArray::from_data(data_type, remainder); + let array = NullArray::new(data_type, remainder); Box::new(complete.chain(std::iter::once(Ok(Arc::new(array) as Arc)))) } } diff --git a/src/io/parquet/read/deserialize/primitive/dictionary.rs b/src/io/parquet/read/deserialize/primitive/dictionary.rs index bf6e4d4b9b3..b3a9a9cc521 100644 --- a/src/io/parquet/read/deserialize/primitive/dictionary.rs +++ b/src/io/parquet/read/deserialize/primitive/dictionary.rs @@ -30,7 +30,7 @@ where .unwrap(); let values = dict.values().iter().map(|x| (op)(*x)).collect::>(); - Arc::new(PrimitiveArray::from_data(data_type, values.into(), None)) + Arc::new(PrimitiveArray::new(data_type, values.into(), None)) } /// An iterator adapter over [`DataPages`] assumed to be encoded as boolean arrays diff --git a/src/io/parquet/read/deserialize/simple.rs b/src/io/parquet/read/deserialize/simple.rs index 58cc7dbca6f..9544f16bff1 100644 --- a/src/io/parquet/read/deserialize/simple.rs +++ b/src/io/parquet/read/deserialize/simple.rs @@ -172,11 +172,7 @@ pub fn page_iter_to_arrays<'a, I: 'a + DataPages>( .collect::>(); let validity = array.validity().cloned(); - Ok(PrimitiveArray::::from_data( - data_type.clone(), - values.into(), - validity, - )) + PrimitiveArray::::try_new(data_type.clone(), values.into(), validity) }); let arrays = pages.map(|x| x.map(|x| Arc::new(x) as Arc)); diff --git a/src/io/parquet/write/mod.rs b/src/io/parquet/write/mod.rs index 8bebbd8e293..7ddf3c19b75 100644 --- a/src/io/parquet/write/mod.rs +++ b/src/io/parquet/write/mod.rs @@ -216,7 +216,7 @@ pub fn array_to_page( values.extend_from_slice(bytes); values.resize(values.len() + 8, 0); }); - let array = FixedSizeBinaryArray::from_data( + let array = FixedSizeBinaryArray::new( DataType::FixedSizeBinary(12), values.into(), array.validity().cloned(), @@ -255,20 +255,14 @@ pub fn array_to_page( if precision <= 9 { let values = array.values().iter().map(|x| *x as i32); let values = Buffer::from_trusted_len_iter(values); - let array = PrimitiveArray::::from_data( - DataType::Int32, - values, - array.validity().cloned(), - ); + let array = + PrimitiveArray::::new(DataType::Int32, values, array.validity().cloned()); primitive::array_to_page::(&array, options, descriptor) } else if precision <= 18 { let values = array.values().iter().map(|x| *x as i64); let values = Buffer::from_trusted_len_iter(values); - let array = PrimitiveArray::::from_data( - DataType::Int64, - values, - array.validity().cloned(), - ); + let array = + PrimitiveArray::::new(DataType::Int64, values, array.validity().cloned()); primitive::array_to_page::(&array, options, descriptor) } else { let size = decimal_length_from_precision(precision);