From 06f8f3634b05bf60291a7df458dc8b20ceccd1ec Mon Sep 17 00:00:00 2001 From: Jorge Leitao Date: Thu, 2 Jun 2022 19:22:12 +0200 Subject: [PATCH] Added .arced/.boxe (#1040) --- examples/csv_write_parallel.rs | 2 +- examples/ffi.rs | 2 +- examples/ipc_file_write.rs | 2 +- examples/parquet_write.rs | 2 +- examples/parquet_write_parallel/src/main.rs | 5 +- src/array/binary/mod.rs | 10 ++++ src/array/boolean/mod.rs | 10 ++++ src/array/dictionary/mod.rs | 10 ++++ src/array/fixed_size_binary/mod.rs | 10 ++++ src/array/fixed_size_list/mod.rs | 10 ++++ src/array/list/mod.rs | 10 ++++ src/array/map/mod.rs | 10 ++++ src/array/null.rs | 10 ++++ src/array/primitive/mod.rs | 10 ++++ src/array/struct_/mod.rs | 14 ++++- src/array/union/mod.rs | 10 ++++ src/array/utf8/mod.rs | 10 ++++ src/doc/lib.md | 5 +- src/io/ipc/mod.rs | 4 +- src/io/ipc/read/deserialize.rs | 20 +++---- src/io/ipc/write/file_async.rs | 2 +- src/io/ipc/write/stream_async.rs | 2 +- .../parquet/read/deserialize/boolean/mod.rs | 6 +-- src/io/parquet/read/deserialize/null.rs | 14 ++--- .../parquet/read/deserialize/primitive/mod.rs | 7 +-- src/io/parquet/read/deserialize/simple.rs | 2 +- src/io/parquet/write/pages.rs | 16 +++--- src/io/parquet/write/sink.rs | 2 +- tests/it/array/growable/union.rs | 10 ++-- tests/it/array/struct_/iterator.rs | 5 +- tests/it/array/struct_/mod.rs | 5 +- tests/it/array/union.rs | 38 +++++++------- tests/it/compute/take.rs | 10 +--- tests/it/ffi/data.rs | 2 +- tests/it/io/avro/read.rs | 2 +- tests/it/io/csv/write.rs | 52 +++++++++---------- tests/it/io/ipc/write/file.rs | 13 ++--- tests/it/io/ipc/write/file_append.rs | 9 +--- tests/it/io/ndjson/mod.rs | 21 +++----- tests/it/io/ndjson/read.rs | 4 +- tests/it/io/parquet/mod.rs | 31 +++++------ tests/it/io/parquet/read_indexes.rs | 18 +++---- tests/it/io/parquet/write_async.rs | 9 ++-- tests/it/io/print.rs | 8 +-- tests/it/scalar/fixed_size_list.rs | 13 ++--- tests/it/scalar/list.rs | 13 ++--- 46 files changed, 265 insertions(+), 215 deletions(-) diff --git a/examples/csv_write_parallel.rs b/examples/csv_write_parallel.rs index 8e2427632e5..4db8683c285 100644 --- a/examples/csv_write_parallel.rs +++ b/examples/csv_write_parallel.rs @@ -59,7 +59,7 @@ fn main() -> Result<()> { Some(5), Some(6), ]); - let columns = Chunk::new(vec![Arc::new(array) as Arc]); + let columns = Chunk::new(vec![array.arced()]); parallel_write("example.csv", [columns.clone(), columns]) } diff --git a/examples/ffi.rs b/examples/ffi.rs index d2f3c68fc28..3356e554cdb 100644 --- a/examples/ffi.rs +++ b/examples/ffi.rs @@ -22,7 +22,7 @@ unsafe fn import(array: Box, schema: &ffi::ArrowSchema) -> Resu fn main() -> Result<()> { // let's assume that we have an array: - let array = Arc::new(PrimitiveArray::::from([Some(1), None, Some(123)])) as Arc; + let array = PrimitiveArray::::from([Some(1), None, Some(123)]).arced(); // the goal is to export this array and import it back via FFI. // to import, we initialize the structs that will receive the data diff --git a/examples/ipc_file_write.rs b/examples/ipc_file_write.rs index a1e4e43e2ec..bea0ef85122 100644 --- a/examples/ipc_file_write.rs +++ b/examples/ipc_file_write.rs @@ -35,7 +35,7 @@ fn main() -> Result<()> { let a = Int32Array::from_slice(&[1, 2, 3, 4, 5]); let b = Utf8Array::::from_slice(&["a", "b", "c", "d", "e"]); - let batch = Chunk::try_new(vec![Arc::new(a) as Arc, Arc::new(b)])?; + let batch = Chunk::try_new(vec![a.arced(), b.arced()])?; // write it write_batches(file_path, schema, &[batch])?; diff --git a/examples/parquet_write.rs b/examples/parquet_write.rs index b3baf3bf8fc..5237baf246b 100644 --- a/examples/parquet_write.rs +++ b/examples/parquet_write.rs @@ -53,7 +53,7 @@ fn main() -> Result<()> { ]); let field = Field::new("c1", array.data_type().clone(), true); let schema = Schema::from(vec![field]); - let columns = Chunk::new(vec![Arc::new(array) as Arc]); + let columns = Chunk::new(vec![array.arced()]); write_batch("test.parquet", schema, columns) } diff --git a/examples/parquet_write_parallel/src/main.rs b/examples/parquet_write_parallel/src/main.rs index b928a1428c5..4939905a76f 100644 --- a/examples/parquet_write_parallel/src/main.rs +++ b/examples/parquet_write_parallel/src/main.rs @@ -134,10 +134,7 @@ fn create_batch(size: usize) -> Result { }) .collect(); - Chunk::try_new(vec![ - Arc::new(c1) as Arc, - Arc::new(c2) as Arc, - ]) + Chunk::try_new(vec![c1.arced(), c2.arced()]) } fn main() -> Result<()> { diff --git a/src/array/binary/mod.rs b/src/array/binary/mod.rs index 1805e5e33f3..9f3c5dad675 100644 --- a/src/array/binary/mod.rs +++ b/src/array/binary/mod.rs @@ -130,6 +130,16 @@ impl BinaryArray { DataType::Binary } } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } // unsafe constructors diff --git a/src/array/boolean/mod.rs b/src/array/boolean/mod.rs index 6a7c9e27d8b..f25c044ae35 100644 --- a/src/array/boolean/mod.rs +++ b/src/array/boolean/mod.rs @@ -82,6 +82,16 @@ impl BooleanArray { let bitmap = Bitmap::new_zeroed(length); Self::new(data_type, bitmap.clone(), Some(bitmap)) } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } // must use diff --git a/src/array/dictionary/mod.rs b/src/array/dictionary/mod.rs index 8e9a01f6a8f..8bda284c1ec 100644 --- a/src/array/dictionary/mod.rs +++ b/src/array/dictionary/mod.rs @@ -161,6 +161,16 @@ impl DictionaryArray { new_scalar(self.values.as_ref(), index) } } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } impl DictionaryArray { diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 8ed5c5cec30..0c25fbd2e77 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -93,6 +93,16 @@ impl FixedSizeBinaryArray { Some(Bitmap::new_zeroed(length)), ) } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } // must use diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index 23a40253c5d..f8faa3598a2 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -111,6 +111,16 @@ impl FixedSizeListArray { .into(); Self::new(data_type, values, Some(Bitmap::new_zeroed(length))) } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } // must use diff --git a/src/array/list/mod.rs b/src/array/list/mod.rs index c5ab495559f..0ef4d882808 100644 --- a/src/array/list/mod.rs +++ b/src/array/list/mod.rs @@ -121,6 +121,16 @@ impl ListArray { Some(Bitmap::new_zeroed(length)), ) } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } // unsafe construtors diff --git a/src/array/map/mod.rs b/src/array/map/mod.rs index 2c667b29583..4c7e4754fd5 100644 --- a/src/array/map/mod.rs +++ b/src/array/map/mod.rs @@ -117,6 +117,16 @@ impl MapArray { let field = new_empty_array(Self::get_field(&data_type).data_type().clone()).into(); Self::new(data_type, Buffer::from(vec![0i32]), field, None) } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } impl MapArray { diff --git a/src/array/null.rs b/src/array/null.rs index dbf5274bdd0..57c9f00210a 100644 --- a/src/array/null.rs +++ b/src/array/null.rs @@ -51,6 +51,16 @@ impl NullArray { pub fn new_null(data_type: DataType, length: usize) -> Self { Self::new(data_type, length) } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } impl NullArray { diff --git a/src/array/primitive/mod.rs b/src/array/primitive/mod.rs index 7ba44345cee..5270be8ea88 100644 --- a/src/array/primitive/mod.rs +++ b/src/array/primitive/mod.rs @@ -356,6 +356,16 @@ impl PrimitiveArray { MutablePrimitiveArray::::from_trusted_len_iter_unchecked(iter).into() } + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } + /// Alias for `Self::try_new(..).unwrap()`. /// # Panics /// This function errors iff: diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs index 43d5d834524..4736a23262a 100644 --- a/src/array/struct_/mod.rs +++ b/src/array/struct_/mod.rs @@ -19,8 +19,8 @@ mod iterator; /// use std::sync::Arc; /// use arrow2::array::*; /// use arrow2::datatypes::*; -/// let boolean = Arc::new(BooleanArray::from_slice(&[false, false, true, true])) as Arc; -/// let int = Arc::new(Int32Array::from_slice(&[42, 28, 19, 31])) as Arc; +/// let boolean = BooleanArray::from_slice(&[false, false, true, true]).arced(); +/// let int = Int32Array::from_slice(&[42, 28, 19, 31]).arced(); /// /// let fields = vec![ /// Field::new("b", DataType::Boolean, false), @@ -223,6 +223,16 @@ impl StructArray { arr.validity = validity; arr } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } // Accessors diff --git a/src/array/union/mod.rs b/src/array/union/mod.rs index dfd87ef6af0..f008f15af70 100644 --- a/src/array/union/mod.rs +++ b/src/array/union/mod.rs @@ -176,6 +176,16 @@ impl UnionArray { panic!("Union struct must be created with the corresponding Union DataType") } } + + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } } impl UnionArray { diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index 8c8813c14b5..088e77076f6 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -216,6 +216,16 @@ impl Utf8Array { } } + /// Boxes self into a [`Box`]. + pub fn boxed(self) -> Box { + Box::new(self) + } + + /// Boxes self into a [`std::sync::Arc`]. + pub fn arced(self) -> std::sync::Arc { + std::sync::Arc::new(self) + } + /// Clones this [`Utf8Array`] and assigns it a new validity /// # Panic /// This function panics iff `validity.len() != self.len()`. diff --git a/src/doc/lib.md b/src/doc/lib.md index dbb013cfbd6..ae4dd9a9cd0 100644 --- a/src/doc/lib.md +++ b/src/doc/lib.md @@ -34,10 +34,7 @@ fn main() -> Result<()> { ]); // declare chunk - let chunk = Chunk::new(vec![ - Arc::new(a) as Arc, - Arc::new(b) as Arc, - ]); + let chunk = Chunk::new(vec![a.arced(), b.arced()]); // write to parquet (probably the fastest implementation of writing to parquet out there) diff --git a/src/io/ipc/mod.rs b/src/io/ipc/mod.rs index f8bfb147104..6877a5574bd 100644 --- a/src/io/ipc/mod.rs +++ b/src/io/ipc/mod.rs @@ -48,9 +48,7 @@ //! // Setup the data //! let x_data = Int32Array::from_slice([-1i32, 1]); //! let y_data = Int32Array::from_slice([1i32, -1]); -//! let chunk = Chunk::try_new( -//! vec![Arc::new(x_data) as Arc, Arc::new(y_data)] -//! )?; +//! let chunk = Chunk::try_new(vec![x_data.arced(), y_data.arced()])?; //! //! // Write the messages and finalize the stream //! for _ in 0..5 { diff --git a/src/io/ipc/read/deserialize.rs b/src/io/ipc/read/deserialize.rs index 56bd0632128..7873f0b9f20 100644 --- a/src/io/ipc/read/deserialize.rs +++ b/src/io/ipc/read/deserialize.rs @@ -32,7 +32,7 @@ pub fn read( let data_type = field.data_type.clone(); match data_type.to_physical_type() { - Null => read_null(field_nodes, data_type).map(|x| Arc::new(x) as Arc), + Null => read_null(field_nodes, data_type).map(|x| x.arced()), Boolean => read_boolean( field_nodes, data_type, @@ -42,7 +42,7 @@ pub fn read( is_little_endian, compression, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), Primitive(primitive) => with_match_primitive_type!(primitive, |$T| { read_primitive::<$T, _>( field_nodes, @@ -53,7 +53,7 @@ pub fn read( is_little_endian, compression, ) - .map(|x| Arc::new(x) as Arc) + .map(|x| x.arced()) }), Binary => { let array = read_binary::( @@ -127,7 +127,7 @@ pub fn read( compression, version, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), LargeList => read_list::( field_nodes, data_type, @@ -140,7 +140,7 @@ pub fn read( compression, version, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), FixedSizeList => read_fixed_size_list( field_nodes, data_type, @@ -153,7 +153,7 @@ pub fn read( compression, version, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), Struct => read_struct( field_nodes, data_type, @@ -166,7 +166,7 @@ pub fn read( compression, version, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), Dictionary(key_type) => { match_integer_type!(key_type, |$T| { read_dictionary::<$T, _>( @@ -179,7 +179,7 @@ pub fn read( compression, is_little_endian, ) - .map(|x| Arc::new(x) as Arc) + .map(|x| x.arced()) }) } Union => read_union( @@ -194,7 +194,7 @@ pub fn read( compression, version, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), Map => read_map( field_nodes, data_type, @@ -207,7 +207,7 @@ pub fn read( compression, version, ) - .map(|x| Arc::new(x) as Arc), + .map(|x| x.arced()), } } diff --git a/src/io/ipc/write/file_async.rs b/src/io/ipc/write/file_async.rs index fdde1e33fa9..3a1e5fbd87e 100644 --- a/src/io/ipc/write/file_async.rs +++ b/src/io/ipc/write/file_async.rs @@ -46,7 +46,7 @@ type WriteOutput = (usize, Option, Vec, Option); /// // Write chunks to file /// for i in 0..3 { /// let values = Int32Array::from(&[Some(i), None]); -/// let chunk = Chunk::new(vec![Arc::new(values) as Arc]); +/// let chunk = Chunk::new(vec![values.arced()]); /// sink.feed(chunk.into()).await?; /// } /// sink.close().await?; diff --git a/src/io/ipc/write/stream_async.rs b/src/io/ipc/write/stream_async.rs index 8b82a6597b1..238bc5338d0 100644 --- a/src/io/ipc/write/stream_async.rs +++ b/src/io/ipc/write/stream_async.rs @@ -41,7 +41,7 @@ use crate::error::{Error, Result}; /// /// for i in 0..3 { /// let values = Int32Array::from(&[Some(i), None]); -/// let chunk = Chunk::new(vec![Arc::new(values) as Arc]); +/// let chunk = Chunk::new(vec![values.arced()]); /// sink.feed(chunk.into()).await?; /// } /// sink.close().await?; diff --git a/src/io/parquet/read/deserialize/boolean/mod.rs b/src/io/parquet/read/deserialize/boolean/mod.rs index ab663682eba..e928c86b56a 100644 --- a/src/io/parquet/read/deserialize/boolean/mod.rs +++ b/src/io/parquet/read/deserialize/boolean/mod.rs @@ -1,10 +1,6 @@ mod basic; mod nested; -use std::sync::Arc; - -use crate::array::Array; - use self::nested::ArrayIterator; use super::{ nested_utils::{InitNested, NestedArrayIter}, @@ -25,7 +21,7 @@ where Box::new(ArrayIterator::new(iter, init, chunk_size).map(|x| { x.map(|(mut nested, array)| { let _ = nested.nested.pop().unwrap(); // the primitive - let values = Arc::new(array) as Arc; + let values = array.arced(); (nested, values) }) })) diff --git a/src/io/parquet/read/deserialize/null.rs b/src/io/parquet/read/deserialize/null.rs index 363663c8ec1..d8e050676be 100644 --- a/src/io/parquet/read/deserialize/null.rs +++ b/src/io/parquet/read/deserialize/null.rs @@ -1,9 +1,4 @@ -use std::sync::Arc; - -use crate::{ - array::{Array, NullArray}, - datatypes::DataType, -}; +use crate::{array::NullArray, datatypes::DataType}; use super::super::{ArrayIter, DataPages}; @@ -21,13 +16,12 @@ where let complete_chunks = chunk_size / len; let remainder = chunk_size % len; let i_data_type = data_type.clone(); - let complete = (0..complete_chunks).map(move |_| { - Ok(Arc::new(NullArray::new(i_data_type.clone(), chunk_size)) as Arc) - }); + let complete = (0..complete_chunks) + .map(move |_| Ok(NullArray::new(i_data_type.clone(), chunk_size).arced())); if len % chunk_size == 0 { Box::new(complete) } else { let array = NullArray::new(data_type, remainder); - Box::new(complete.chain(std::iter::once(Ok(Arc::new(array) as Arc)))) + Box::new(complete.chain(std::iter::once(Ok(array.arced())))) } } diff --git a/src/io/parquet/read/deserialize/primitive/mod.rs b/src/io/parquet/read/deserialize/primitive/mod.rs index 400b87f1040..44ab76fa4d0 100644 --- a/src/io/parquet/read/deserialize/primitive/mod.rs +++ b/src/io/parquet/read/deserialize/primitive/mod.rs @@ -4,9 +4,7 @@ mod nested; pub use dictionary::DictIter; -use std::sync::Arc; - -use crate::{array::Array, datatypes::DataType}; +use crate::datatypes::DataType; use super::{nested_utils::*, DataPages}; @@ -31,8 +29,7 @@ where ArrayIterator::::new(iter, init, data_type, chunk_size, op).map(|x| { x.map(|(mut nested, array)| { let _ = nested.nested.pop().unwrap(); // the primitive - let values = Arc::new(array) as Arc; - (nested, values) + (nested, array.arced()) }) }), ) diff --git a/src/io/parquet/read/deserialize/simple.rs b/src/io/parquet/read/deserialize/simple.rs index da83b3b861f..fe895c326f1 100644 --- a/src/io/parquet/read/deserialize/simple.rs +++ b/src/io/parquet/read/deserialize/simple.rs @@ -165,7 +165,7 @@ pub fn page_iter_to_arrays<'a, I: 'a + DataPages>( PrimitiveArray::::try_new(data_type.clone(), values.into(), validity) }); - let arrays = pages.map(|x| x.map(|x| Arc::new(x) as Arc)); + let arrays = pages.map(|x| x.map(|x| x.arced())); Box::new(arrays) as _ } diff --git a/src/io/parquet/write/pages.rs b/src/io/parquet/write/pages.rs index e666c8df05f..1f3cac6434f 100644 --- a/src/io/parquet/write/pages.rs +++ b/src/io/parquet/write/pages.rs @@ -234,10 +234,8 @@ mod tests { #[test] fn test_struct() { - use std::sync::Arc; - let boolean = - Arc::new(BooleanArray::from_slice(&[false, false, true, true])) as Arc; - let int = Arc::new(Int32Array::from_slice(&[42, 28, 19, 31])) as Arc; + let boolean = BooleanArray::from_slice(&[false, false, true, true]).arced(); + let int = Int32Array::from_slice(&[42, 28, 19, 31]).arced(); let fields = vec![ Field::new("b", DataType::Boolean, false), @@ -301,9 +299,8 @@ mod tests { #[test] fn test_struct_struct() { use std::sync::Arc; - let boolean = - Arc::new(BooleanArray::from_slice(&[false, false, true, true])) as Arc; - let int = Arc::new(Int32Array::from_slice(&[42, 28, 19, 31])) as Arc; + let boolean = BooleanArray::from_slice(&[false, false, true, true]).arced(); + let int = Int32Array::from_slice(&[42, 28, 19, 31]).arced(); let fields = vec![ Field::new("b", DataType::Boolean, false), @@ -406,9 +403,8 @@ mod tests { #[test] fn test_list_struct() { use std::sync::Arc; - let boolean = - Arc::new(BooleanArray::from_slice(&[false, false, true, true])) as Arc; - let int = Arc::new(Int32Array::from_slice(&[42, 28, 19, 31])) as Arc; + let boolean = BooleanArray::from_slice(&[false, false, true, true]).arced(); + let int = Int32Array::from_slice(&[42, 28, 19, 31]).arced(); let fields = vec![ Field::new("b", DataType::Boolean, false), diff --git a/src/io/parquet/write/sink.rs b/src/io/parquet/write/sink.rs index 1f3e44fa648..2995c7a8037 100644 --- a/src/io/parquet/write/sink.rs +++ b/src/io/parquet/write/sink.rs @@ -47,7 +47,7 @@ use super::{Encoding, SchemaDescriptor, WriteOptions}; /// /// for i in 0..3 { /// let values = Int32Array::from(&[Some(i), None]); -/// let chunk = Chunk::new(vec![Arc::new(values) as Arc]); +/// let chunk = Chunk::new(vec![values.arced()]); /// sink.feed(chunk).await?; /// } /// sink.metadata.insert(String::from("key"), Some(String::from("value"))); diff --git a/tests/it/array/growable/union.rs b/tests/it/array/growable/union.rs index e670bc1a750..eb513c2c217 100644 --- a/tests/it/array/growable/union.rs +++ b/tests/it/array/growable/union.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use arrow2::{ array::{ growable::{Growable, GrowableUnion}, @@ -18,8 +16,8 @@ fn sparse() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Sparse); let types = vec![0, 0, 1].into(); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields, None); @@ -48,8 +46,8 @@ fn dense() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Dense); let types = vec![0, 0, 1].into(); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("c")]).arced(), ]; let offsets = Some(vec![0, 1, 0].into()); diff --git a/tests/it/array/struct_/iterator.rs b/tests/it/array/struct_/iterator.rs index dac0c16b6ec..a73fc500654 100644 --- a/tests/it/array/struct_/iterator.rs +++ b/tests/it/array/struct_/iterator.rs @@ -4,9 +4,8 @@ use arrow2::scalar::new_scalar; #[test] fn test_simple_iter() { - use std::sync::Arc; - let boolean = Arc::new(BooleanArray::from_slice(&[false, false, true, true])) as Arc; - let int = Arc::new(Int32Array::from_slice(&[42, 28, 19, 31])) as Arc; + let boolean = BooleanArray::from_slice(&[false, false, true, true]).arced(); + let int = Int32Array::from_slice(&[42, 28, 19, 31]).arced(); let fields = vec![ Field::new("b", DataType::Boolean, false), diff --git a/tests/it/array/struct_/mod.rs b/tests/it/array/struct_/mod.rs index cd88fb8933e..23862c37471 100644 --- a/tests/it/array/struct_/mod.rs +++ b/tests/it/array/struct_/mod.rs @@ -6,9 +6,8 @@ use arrow2::datatypes::*; #[test] fn debug() { - use std::sync::Arc; - let boolean = Arc::new(BooleanArray::from_slice(&[false, false, true, true])) as Arc; - let int = Arc::new(Int32Array::from_slice(&[42, 28, 19, 31])) as Arc; + let boolean = BooleanArray::from_slice(&[false, false, true, true]).arced(); + let int = Int32Array::from_slice(&[42, 28, 19, 31]).arced(); let fields = vec![ Field::new("b", DataType::Boolean, false), diff --git a/tests/it/array/union.rs b/tests/it/array/union.rs index 6d8a1f54f7a..3f6213f7aa3 100644 --- a/tests/it/array/union.rs +++ b/tests/it/array/union.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use arrow2::{ array::*, buffer::Buffer, @@ -30,8 +28,8 @@ fn sparse_debug() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Sparse); let types = vec![0, 0, 1].into(); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields, None); @@ -50,8 +48,8 @@ fn dense_debug() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Dense); let types = vec![0, 0, 1].into(); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("c")]).arced(), ]; let offsets = Some(vec![0, 1, 0].into()); @@ -71,8 +69,8 @@ fn slice() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Sparse); let types = Buffer::from(vec![0, 0, 1]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type.clone(), types, fields.clone(), None); @@ -81,8 +79,8 @@ fn slice() -> Result<()> { let sliced_types = Buffer::from(vec![0, 1]); let sliced_fields = vec![ - Arc::new(Int32Array::from(&[None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("b"), Some("c")])) as Arc, + Int32Array::from(&[None, Some(2)]).arced(), + Utf8Array::::from(&[Some("b"), Some("c")]).arced(), ]; let expected = UnionArray::from_data(data_type, sliced_types, sliced_fields, None); @@ -99,8 +97,8 @@ fn iter_sparse() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Sparse); let types = Buffer::from(vec![0, 0, 1]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields.clone(), None); @@ -133,8 +131,8 @@ fn iter_dense() -> Result<()> { let types = Buffer::from(vec![0, 0, 1]); let offsets = Buffer::::from(vec![0, 1, 0]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None])) as Arc, - Arc::new(Utf8Array::::from(&[Some("c")])) as Arc, + Int32Array::from(&[Some(1), None]).arced(), + Utf8Array::::from(&[Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields.clone(), Some(offsets)); @@ -166,8 +164,8 @@ fn iter_sparse_slice() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Sparse); let types = Buffer::from(vec![0, 0, 1]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), Some(3), Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), Some(3), Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields.clone(), None); @@ -193,8 +191,8 @@ fn iter_dense_slice() -> Result<()> { let types = Buffer::from(vec![0, 0, 1]); let offsets = Buffer::::from(vec![0, 1, 0]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), Some(3)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("c")])) as Arc, + Int32Array::from(&[Some(1), Some(3)]).arced(), + Utf8Array::::from(&[Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields.clone(), Some(offsets)); @@ -220,8 +218,8 @@ fn scalar() -> Result<()> { let types = Buffer::from(vec![0, 0, 1]); let offsets = Buffer::::from(vec![0, 1, 0]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None])) as Arc, - Arc::new(Utf8Array::::from(&[Some("c")])) as Arc, + Int32Array::from(&[Some(1), None]).arced(), + Utf8Array::::from(&[Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields.clone(), Some(offsets)); diff --git a/tests/it/compute/take.rs b/tests/it/compute/take.rs index f2f5c1bd39b..b707c22d339 100644 --- a/tests/it/compute/take.rs +++ b/tests/it/compute/take.rs @@ -75,10 +75,7 @@ fn create_test_struct() -> StructArray { ]; StructArray::from_data( DataType::Struct(fields), - vec![ - Arc::new(boolean) as Arc, - Arc::new(int) as Arc, - ], + vec![boolean.arced(), int.arced()], validity, ) } @@ -99,10 +96,7 @@ fn test_struct_with_nulls() { .into(); let expected = StructArray::from_data( array.data_type().clone(), - vec![ - Arc::new(boolean) as Arc, - Arc::new(int) as Arc, - ], + vec![boolean.arced(), int.arced()], validity, ); assert_eq!(expected, output.as_ref()); diff --git a/tests/it/ffi/data.rs b/tests/it/ffi/data.rs index 08f2334293b..f4880161ab8 100644 --- a/tests/it/ffi/data.rs +++ b/tests/it/ffi/data.rs @@ -308,7 +308,7 @@ fn list_list() -> Result<()> { #[test] fn struct_() -> Result<()> { let data_type = DataType::Struct(vec![Field::new("a", DataType::Int32, true)]); - let values = vec![Arc::new(Int32Array::from([Some(1), None, Some(3)])) as Arc]; + let values = vec![Int32Array::from([Some(1), None, Some(3)]).arced()]; let validity = Bitmap::from([true, false, true]); let array = StructArray::from_data(data_type, values, validity.into()); diff --git a/tests/it/io/avro/read.rs b/tests/it/io/avro/read.rs index 1c5fc567480..57e40663513 100644 --- a/tests/it/io/avro/read.rs +++ b/tests/it/io/avro/read.rs @@ -93,7 +93,7 @@ pub(super) fn data() -> Chunk> { array.try_extend(data).unwrap(); let columns = vec![ - Arc::new(Int64Array::from_slice([27, 47])) as Arc, + Int64Array::from_slice([27, 47]).arced(), Arc::new(Utf8Array::::from_slice(["foo", "bar"])), Arc::new(Int32Array::from_slice([1, 1])), Arc::new(Int32Array::from_slice([1, 2]).to(DataType::Date32)), diff --git a/tests/it/io/csv/write.rs b/tests/it/io/csv/write.rs index e174bb5256d..817db76bd1b 100644 --- a/tests/it/io/csv/write.rs +++ b/tests/it/io/csv/write.rs @@ -88,54 +88,54 @@ d|-556132.25|1||2019-04-18 02:45:55.555|11:46:03 PM|c fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { let (array, expected) = match column { 0 => ( - Arc::new(Utf8Array::::from_slice(["a b", "c", "d"])) as Arc, + Utf8Array::::from_slice(["a b", "c", "d"]).arced(), vec!["a b", "c", "d"], ), 1 => ( - Arc::new(BinaryArray::::from_slice(["a b", "c", "d"])) as Arc, + BinaryArray::::from_slice(["a b", "c", "d"]).arced(), vec!["a b", "c", "d"], ), 2 => ( - Arc::new(BinaryArray::::from_slice(["a b", "c", "d"])) as Arc, + BinaryArray::::from_slice(["a b", "c", "d"]).arced(), vec!["a b", "c", "d"], ), 3 => ( - Arc::new(Int8Array::from_slice(&[3, 2, 1])) as Arc, + Int8Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 4 => ( - Arc::new(Int16Array::from_slice(&[3, 2, 1])) as Arc, + Int16Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 5 => ( - Arc::new(Int32Array::from_slice(&[3, 2, 1])) as Arc, + Int32Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 6 => ( - Arc::new(Int64Array::from_slice(&[3, 2, 1])) as Arc, + Int64Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 7 => ( - Arc::new(UInt8Array::from_slice(&[3, 2, 1])) as Arc, + UInt8Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 8 => ( - Arc::new(UInt16Array::from_slice(&[3, 2, 1])) as Arc, + UInt16Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 9 => ( - Arc::new(UInt32Array::from_slice(&[3, 2, 1])) as Arc, + UInt32Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 10 => ( - Arc::new(UInt64Array::from_slice(&[3, 2, 1])) as Arc, + UInt64Array::from_slice(&[3, 2, 1]).arced(), vec!["3", "2", "1"], ), 11 => { let array = PrimitiveArray::::from_vec(vec![1_234_001, 24_680_001, 85_563_001]) .to(DataType::Time32(TimeUnit::Millisecond)); ( - Arc::new(array) as Arc, + array.arced(), vec!["00:20:34.001", "06:51:20.001", "23:46:03.001"], ) } @@ -147,7 +147,7 @@ fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { ]) .to(DataType::Time64(TimeUnit::Microsecond)); ( - Arc::new(array) as Arc, + array.arced(), vec!["00:20:34.000001", "06:51:20.000001", "23:46:03.000001"], ) } @@ -159,7 +159,7 @@ fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { ]) .to(DataType::Time64(TimeUnit::Nanosecond)); ( - Arc::new(array) as Arc, + array.arced(), vec![ "00:20:34.000000001", "06:51:20.000000001", @@ -174,7 +174,7 @@ fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { ]) .to(DataType::Timestamp(TimeUnit::Nanosecond, None)); ( - Arc::new(array) as Arc, + array.arced(), vec![ "2019-04-18 10:54:47.378000001", "2019-04-18 02:45:55.555000001", @@ -191,7 +191,7 @@ fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { Some("+01:00".to_string()), )); ( - Arc::new(array) as Arc, + array.arced(), vec![ "2019-04-18 11:54:47.378000001 +01:00", "2019-04-18 03:45:55.555000001 +01:00", @@ -200,10 +200,9 @@ fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { } 16 => { let keys = UInt32Array::from_slice(&[2, 1, 0]); - let values = - Arc::new(Utf8Array::::from_slice(["a b", "c", "d"])) as Arc; + let values = Utf8Array::::from_slice(["a b", "c", "d"]).arced(); let array = DictionaryArray::from_data(keys, values); - (Arc::new(array) as Arc, vec!["d", "c", "a b"]) + (array.arced(), vec!["d", "c", "a b"]) } 17 => { let array = PrimitiveArray::::from_slice([ @@ -215,7 +214,7 @@ fn data_array(column: usize) -> (Chunk>, Vec<&'static str>) { Some("Europe/Lisbon".to_string()), )); ( - Arc::new(array) as Arc, + array.arced(), vec![ "2019-04-18 11:54:47.378000001 WEST", "2019-04-18 03:45:55.555000001 WEST", @@ -277,7 +276,7 @@ fn write_tz_timezone_formatted_offset() -> Result<()> { Some("+01:00".to_string()), )); - let columns = Chunk::new(vec![Arc::new(array) as Arc]); + let columns = Chunk::new(vec![array.arced()]); let expected = vec![ "2019-04-18T11:54:47.378000001+01:00", "2019-04-18T03:45:55.555000001+01:00", @@ -302,7 +301,7 @@ fn write_tz_timezone_formatted_tz() -> Result<()> { Some("Europe/Lisbon".to_string()), )); - let columns = Chunk::new(vec![Arc::new(array) as Arc]); + let columns = Chunk::new(vec![array.arced()]); let expected = vec![ "2019-04-18T11:54:47.378000001+01:00", "2019-04-18T03:45:55.555000001+01:00", @@ -321,10 +320,7 @@ fn write_tz_timezone_formatted_tz() -> Result<()> { fn write_empty_and_missing() { let a = Utf8Array::::from(&[Some(""), None]); let b = Utf8Array::::from(&[None, Some("")]); - let columns = Chunk::new(vec![ - Arc::new(a) as Arc, - Arc::new(b) as Arc, - ]); + let columns = Chunk::new(vec![a.arced(), b.arced()]); let mut writer = vec![]; let options = SerializeOptions::default(); @@ -337,7 +333,7 @@ fn write_empty_and_missing() { #[test] fn write_escaping() { let a = Utf8Array::::from_slice(&["Acme co., Ltd."]); - let columns = Chunk::new(vec![Arc::new(a) as Arc]); + let columns = Chunk::new(vec![a.arced()]); let mut writer = vec![]; let options = SerializeOptions::default(); @@ -357,7 +353,7 @@ fn write_escaping_resize_local_buf() { let a = Utf8Array::::from_slice(&[ payload ]); - let columns = Chunk::new(vec![Arc::new(a) as Arc]); + let columns = Chunk::new(vec![a.arced()]); let mut writer = vec![]; let options = SerializeOptions::default(); diff --git a/tests/it/io/ipc/write/file.rs b/tests/it/io/ipc/write/file.rs index d76855fdd93..42aea0d0b3d 100644 --- a/tests/it/io/ipc/write/file.rs +++ b/tests/it/io/ipc/write/file.rs @@ -327,13 +327,7 @@ fn write_generated_017_union() -> Result<()> { #[test] #[cfg_attr(miri, ignore)] // compression uses FFI, which miri does not support fn write_boolean() -> Result<()> { - use std::sync::Arc; - let array = Arc::new(BooleanArray::from([ - Some(true), - Some(false), - None, - Some(true), - ])) as Arc; + let array = BooleanArray::from([Some(true), Some(false), None, Some(true)]).arced(); let schema = Schema::from(vec![Field::new("a", array.data_type().clone(), true)]); let columns = Chunk::try_new(vec![array])?; round_trip(columns, schema, None, Some(Compression::ZSTD)) @@ -342,8 +336,9 @@ fn write_boolean() -> Result<()> { #[test] #[cfg_attr(miri, ignore)] // compression uses FFI, which miri does not support fn write_sliced_utf8() -> Result<()> { - use std::sync::Arc; - let array = Arc::new(Utf8Array::::from_slice(["aa", "bb"]).slice(1, 1)) as Arc; + let array = Utf8Array::::from_slice(["aa", "bb"]) + .slice(1, 1) + .arced(); let schema = Schema::from(vec![Field::new("a", array.data_type().clone(), true)]); let columns = Chunk::try_new(vec![array])?; round_trip(columns, schema, None, Some(Compression::ZSTD)) diff --git a/tests/it/io/ipc/write/file_append.rs b/tests/it/io/ipc/write/file_append.rs index 02573ebb634..337360a8717 100644 --- a/tests/it/io/ipc/write/file_append.rs +++ b/tests/it/io/ipc/write/file_append.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use arrow2::array::*; use arrow2::chunk::Chunk; use arrow2::datatypes::*; @@ -12,12 +10,7 @@ use super::file::write; #[test] fn basic() -> Result<()> { // prepare some data - let array = Arc::new(BooleanArray::from([ - Some(true), - Some(false), - None, - Some(true), - ])) as Arc; + let array = BooleanArray::from([Some(true), Some(false), None, Some(true)]).arced(); let schema = Schema::from(vec![Field::new("a", array.data_type().clone(), true)]); let columns = Chunk::try_new(vec![array])?; diff --git a/tests/it/io/ndjson/mod.rs b/tests/it/io/ndjson/mod.rs index 163abc02809..0640e81af2b 100644 --- a/tests/it/io/ndjson/mod.rs +++ b/tests/it/io/ndjson/mod.rs @@ -87,16 +87,11 @@ fn case_list() -> (String, Arc) { let array = StructArray::from_data( data_type, - vec![ - Arc::new(a) as Arc, - Arc::new(b), - Arc::new(c), - Arc::new(d), - ], + vec![a.arced(), b.arced(), c.arced(), d.arced()], None, ); - (data, Arc::new(array)) + (data, array.arced()) } fn case_dict() -> (String, Arc) { @@ -140,7 +135,7 @@ fn case_dict() -> (String, Arc) { data, Arc::new(StructArray::from_data( DataType::Struct(fields), - vec![Arc::new(array) as Arc], + vec![array.arced()], None, )), ) @@ -160,7 +155,7 @@ fn case_basics() -> (String, Arc) { let array = StructArray::from_data( data_type, vec![ - Arc::new(Int64Array::from_slice(&[1, -10, 100000000])) as Arc, + Int64Array::from_slice(&[1, -10, 100000000]).arced(), Arc::new(Float64Array::from_slice(&[2.0, -3.5, 0.6])), Arc::new(BooleanArray::from(&[Some(false), Some(true), None])), Arc::new(Utf8Array::::from(&[Some("4"), None, Some("text")])), @@ -185,7 +180,7 @@ fn case_projection() -> (String, Arc) { let array = StructArray::from_data( data_type, vec![ - Arc::new(UInt32Array::from_slice(&[1, 10, 100000000])) as Arc, + UInt32Array::from_slice(&[1, 10, 100000000]).arced(), Arc::new(Float32Array::from_slice(&[2.0, -3.5, 0.6])), Arc::new(BooleanArray::from(&[Some(false), Some(true), None])), Arc::new(BinaryArray::::from(&[ @@ -240,7 +235,7 @@ fn case_struct() -> (String, Arc) { data, Arc::new(StructArray::from_data( data_type, - vec![Arc::new(expected) as Arc], + vec![expected.arced()], None, )), ) @@ -292,13 +287,13 @@ fn case_nested_list() -> (String, Arc) { ]); let a_struct = StructArray::from_data( DataType::Struct(vec![b_field, c_field]), - vec![Arc::new(b) as Arc, Arc::new(c) as Arc], + vec![b.arced(), c.arced()], None, ); let expected = ListArray::from_data( a_list_data_type, Buffer::from(vec![0i32, 2, 3, 6, 6, 6]), - Arc::new(a_struct) as Arc, + a_struct.arced(), Some(Bitmap::from_u8_slice([0b00010111], 5)), ); diff --git a/tests/it/io/ndjson/read.rs b/tests/it/io/ndjson/read.rs index 6a6900fc140..66ea5e0aba5 100644 --- a/tests/it/io/ndjson/read.rs +++ b/tests/it/io/ndjson/read.rs @@ -99,12 +99,12 @@ fn case_nested_struct() -> (String, Arc) { let data_type = DataType::Struct(vec![Field::new("a", inner.clone(), true)]); let values = vec![ - Arc::new(Float64Array::from([Some(2.0), None, Some(2.0), Some(2.0)])) as Arc, + Float64Array::from([Some(2.0), None, Some(2.0), Some(2.0)]).arced(), Arc::new(Int64Array::from([Some(2), Some(2), Some(2), Some(2)])), Arc::new(BooleanArray::from([None, None, Some(true), None])), ]; - let values = vec![Arc::new(StructArray::from_data(inner, values, None)) as Arc]; + let values = vec![StructArray::from_data(inner, values, None).arced()]; let array = Arc::new(StructArray::from_data(data_type, values, None)); diff --git a/tests/it/io/parquet/mod.rs b/tests/it/io/parquet/mod.rs index 79951951e22..d60796378ce 100644 --- a/tests/it/io/parquet/mod.rs +++ b/tests/it/io/parquet/mod.rs @@ -73,7 +73,7 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box { let values = match column { "list_int64" => { // [[0, 1], None, [2, None, 3], [4, 5, 6], [], [7, 8, 9], None, [10]] - Arc::new(PrimitiveArray::::from(&[ + PrimitiveArray::::from(&[ Some(0), Some(1), Some(2), @@ -86,11 +86,12 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box { Some(8), Some(9), Some(10), - ])) as Arc + ]) + .arced() } "list_int64_required" | "list_int64_optional_required" | "list_int64_required_required" => { // [[0, 1], None, [2, 0, 3], [4, 5, 6], [], [7, 8, 9], None, [10]] - Arc::new(PrimitiveArray::::from(&[ + PrimitiveArray::::from(&[ Some(0), Some(1), Some(2), @@ -103,9 +104,10 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box { Some(8), Some(9), Some(10), - ])) as Arc + ]) + .arced() } - "list_int16" => Arc::new(PrimitiveArray::::from(&[ + "list_int16" => PrimitiveArray::::from(&[ Some(0), Some(1), Some(2), @@ -118,8 +120,9 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box { Some(8), Some(9), Some(10), - ])) as Arc, - "list_bool" => Arc::new(BooleanArray::from(&[ + ]) + .arced(), + "list_bool" => BooleanArray::from(&[ Some(false), Some(true), Some(true), @@ -132,7 +135,8 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box { Some(false), Some(false), Some(true), - ])) as Arc, + ]) + .arced(), /* string = [ ["Hello", "bbb"], @@ -691,7 +695,7 @@ pub fn pyarrow_struct(column: &str) -> Box { Some(true), Some(true), ]; - let boolean = Arc::new(BooleanArray::from(boolean)) as Arc; + let boolean = BooleanArray::from(boolean).arced(); let fields = vec![ Field::new("f1", DataType::Utf8, true), Field::new("f2", DataType::Boolean, true), @@ -710,10 +714,7 @@ pub fn pyarrow_struct(column: &str) -> Box { Some("def"), Some("aaa"), ]; - let values = vec![ - Arc::new(Utf8Array::::from(string)) as Arc, - boolean, - ]; + let values = vec![Utf8Array::::from(string).arced(), boolean]; Box::new(StructArray::from_data( DataType::Struct(fields), values, @@ -870,7 +871,7 @@ fn arrow_type() -> Result<()> { Field::new("a6", array5.data_type().clone(), false), ]); let batch = Chunk::try_new(vec![ - Arc::new(array) as Arc, + array.arced(), Arc::new(array2), Arc::new(array3), Arc::new(array4), @@ -915,7 +916,7 @@ fn list_array_generic(inner_is_nullable: bool, is_nullable: bool) -> Result<()> array.data_type().clone(), is_nullable, )]); - let batch = Chunk::try_new(vec![Arc::new(array) as Arc])?; + let batch = Chunk::try_new(vec![array.arced()])?; let r = integration_write(&schema, &[batch.clone()])?; diff --git a/tests/it/io/parquet/read_indexes.rs b/tests/it/io/parquet/read_indexes.rs index 6dd88618ae9..3f794a1cc56 100644 --- a/tests/it/io/parquet/read_indexes.rs +++ b/tests/it/io/parquet/read_indexes.rs @@ -138,7 +138,7 @@ fn read_with_indexes( fn indexed_required_utf8() -> Result<()> { let array21 = Utf8Array::::from_slice(["a", "b", "c"]); let array22 = Utf8Array::::from_slice(["d", "e", "f"]); - let expected = Arc::new(Utf8Array::::from_slice(["e"])) as Arc; + let expected = Utf8Array::::from_slice(["e"]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -147,7 +147,7 @@ fn indexed_required_utf8() -> Result<()> { fn indexed_required_i32() -> Result<()> { let array21 = Int32Array::from_slice([1, 2, 3]); let array22 = Int32Array::from_slice([4, 5, 6]); - let expected = Arc::new(Int32Array::from_slice([5])) as Arc; + let expected = Int32Array::from_slice([5]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -156,7 +156,7 @@ fn indexed_required_i32() -> Result<()> { fn indexed_optional_i32() -> Result<()> { let array21 = Int32Array::from([Some(1), Some(2), None]); let array22 = Int32Array::from([None, Some(5), Some(6)]); - let expected = Arc::new(Int32Array::from_slice([5])) as Arc; + let expected = Int32Array::from_slice([5]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -165,7 +165,7 @@ fn indexed_optional_i32() -> Result<()> { fn indexed_optional_utf8() -> Result<()> { let array21 = Utf8Array::::from([Some("a"), Some("b"), None]); let array22 = Utf8Array::::from([None, Some("e"), Some("f")]); - let expected = Arc::new(Utf8Array::::from_slice(["e"])) as Arc; + let expected = Utf8Array::::from_slice(["e"]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -174,7 +174,7 @@ fn indexed_optional_utf8() -> Result<()> { fn indexed_required_fixed_len() -> Result<()> { let array21 = FixedSizeBinaryArray::from_slice([[127], [128], [129]]); let array22 = FixedSizeBinaryArray::from_slice([[130], [131], [132]]); - let expected = Arc::new(FixedSizeBinaryArray::from_slice([[131]])) as Arc; + let expected = FixedSizeBinaryArray::from_slice([[131]]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -183,7 +183,7 @@ fn indexed_required_fixed_len() -> Result<()> { fn indexed_optional_fixed_len() -> Result<()> { let array21 = FixedSizeBinaryArray::from([Some([127]), Some([128]), None]); let array22 = FixedSizeBinaryArray::from([None, Some([131]), Some([132])]); - let expected = Arc::new(FixedSizeBinaryArray::from_slice([[131]])) as Arc; + let expected = FixedSizeBinaryArray::from_slice([[131]]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -192,7 +192,7 @@ fn indexed_optional_fixed_len() -> Result<()> { fn indexed_required_boolean() -> Result<()> { let array21 = BooleanArray::from_slice([true, false, true]); let array22 = BooleanArray::from_slice([false, false, true]); - let expected = Arc::new(BooleanArray::from_slice([false])) as Arc; + let expected = BooleanArray::from_slice([false]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -201,7 +201,7 @@ fn indexed_required_boolean() -> Result<()> { fn indexed_optional_boolean() -> Result<()> { let array21 = BooleanArray::from([Some(true), Some(false), None]); let array22 = BooleanArray::from([None, Some(false), Some(true)]); - let expected = Arc::new(BooleanArray::from_slice([false])) as Arc; + let expected = BooleanArray::from_slice([false]).arced(); read_with_indexes(pages(&[&array21, &array22], Encoding::Plain)?, expected) } @@ -216,7 +216,7 @@ fn indexed_dict() -> Result<()> { let values = PrimitiveArray::from_slice([4i32, 6i32]); let expected = DictionaryArray::from_data(indices, std::sync::Arc::new(values)); - let expected = Arc::new(expected) as Arc; + let expected = expected.arced(); read_with_indexes(pages(&[&array], Encoding::RleDictionary)?, expected) } diff --git a/tests/it/io/parquet/write_async.rs b/tests/it/io/parquet/write_async.rs index 158f8c01e08..c322e7c5238 100644 --- a/tests/it/io/parquet/write_async.rs +++ b/tests/it/io/parquet/write_async.rs @@ -1,7 +1,7 @@ -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; use arrow2::{ - array::{Array, Float32Array, Int32Array}, + array::{Float32Array, Int32Array}, chunk::Chunk, datatypes::{DataType, Field, Schema}, error::Result, @@ -20,10 +20,7 @@ async fn test_parquet_async_roundtrip() { for i in 0..5 { let a1 = Int32Array::from(&[Some(i), None, Some(i + 1)]); let a2 = Float32Array::from(&[None, Some(i as f32), None]); - let chunk = Chunk::new(vec![ - Arc::new(a1) as Arc, - Arc::new(a2) as Arc, - ]); + let chunk = Chunk::new(vec![a1.arced(), a2.arced()]); data.push(chunk); } let schema = Schema::from(vec![ diff --git a/tests/it/io/print.rs b/tests/it/io/print.rs index 5b16931a70e..70f9bbf258e 100644 --- a/tests/it/io/print.rs +++ b/tests/it/io/print.rs @@ -323,8 +323,8 @@ fn write_struct() -> Result<()> { Field::new("b", DataType::Utf8, true), ]; let values = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let validity = Some(Bitmap::from(&[true, false, true])); @@ -361,8 +361,8 @@ fn write_union() -> Result<()> { let data_type = DataType::Union(fields, None, UnionMode::Sparse); let types = Buffer::from(vec![0, 0, 1]); let fields = vec![ - Arc::new(Int32Array::from(&[Some(1), None, Some(2)])) as Arc, - Arc::new(Utf8Array::::from(&[Some("a"), Some("b"), Some("c")])) as Arc, + Int32Array::from(&[Some(1), None, Some(2)]).arced(), + Utf8Array::::from(&[Some("a"), Some("b"), Some("c")]).arced(), ]; let array = UnionArray::from_data(data_type, types, fields, None); diff --git a/tests/it/scalar/fixed_size_list.rs b/tests/it/scalar/fixed_size_list.rs index a76b7aca38d..a377d6afa0e 100644 --- a/tests/it/scalar/fixed_size_list.rs +++ b/tests/it/scalar/fixed_size_list.rs @@ -1,7 +1,5 @@ -use std::sync::Arc; - use arrow2::{ - array::{Array, BooleanArray}, + array::BooleanArray, datatypes::{DataType, Field}, scalar::{FixedSizeListScalar, Scalar}, }; @@ -12,7 +10,7 @@ fn equal() { let dt = DataType::FixedSizeList(Box::new(Field::new("a", DataType::Boolean, true)), 2); let a = FixedSizeListScalar::new( dt.clone(), - Some(Arc::new(BooleanArray::from_slice([true, false])) as Arc), + Some(BooleanArray::from_slice([true, false]).arced()), ); let b = FixedSizeListScalar::new(dt.clone(), None); @@ -21,10 +19,7 @@ fn equal() { assert_eq!(b, b); assert!(a != b); - let b = FixedSizeListScalar::new( - dt, - Some(Arc::new(BooleanArray::from_slice([true, true])) as Arc), - ); + let b = FixedSizeListScalar::new(dt, Some(BooleanArray::from_slice([true, true]).arced())); assert!(a != b); assert_eq!(b, b); } @@ -34,7 +29,7 @@ fn basics() { let dt = DataType::FixedSizeList(Box::new(Field::new("a", DataType::Boolean, true)), 2); let a = FixedSizeListScalar::new( dt.clone(), - Some(Arc::new(BooleanArray::from_slice([true, false])) as Arc), + Some(BooleanArray::from_slice([true, false]).arced()), ); assert_eq!( diff --git a/tests/it/scalar/list.rs b/tests/it/scalar/list.rs index 9475a30a580..c0e4243e2f2 100644 --- a/tests/it/scalar/list.rs +++ b/tests/it/scalar/list.rs @@ -1,7 +1,5 @@ -use std::sync::Arc; - use arrow2::{ - array::{Array, BooleanArray}, + array::BooleanArray, datatypes::{DataType, Field}, scalar::{ListScalar, Scalar}, }; @@ -12,16 +10,13 @@ fn equal() { let dt = DataType::List(Box::new(Field::new("a", DataType::Boolean, true))); let a = ListScalar::::new( dt.clone(), - Some(Arc::new(BooleanArray::from_slice([true, false])) as Arc), + Some(BooleanArray::from_slice([true, false]).arced()), ); let b = ListScalar::::new(dt.clone(), None); assert_eq!(a, a); assert_eq!(b, b); assert!(a != b); - let b = ListScalar::::new( - dt, - Some(Arc::new(BooleanArray::from_slice([true, true])) as Arc), - ); + let b = ListScalar::::new(dt, Some(BooleanArray::from_slice([true, true]).arced())); assert!(a != b); assert_eq!(b, b); } @@ -31,7 +26,7 @@ fn basics() { let dt = DataType::List(Box::new(Field::new("a", DataType::Boolean, true))); let a = ListScalar::::new( dt.clone(), - Some(Arc::new(BooleanArray::from_slice([true, false])) as Arc), + Some(BooleanArray::from_slice([true, false]).arced()), ); assert_eq!(BooleanArray::from_slice([true, false]), a.values().as_ref());