From 6818e10c9c67671ced465918740f9fbf6bf24a32 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Thu, 2 Jun 2022 17:41:51 +0000 Subject: [PATCH] Fixes --- arrow-pyarrow-integration-testing/src/c_stream.rs | 5 +++-- examples/cow.rs | 4 ++-- examples/parquet_read_parallel/src/main.rs | 3 +-- guide/src/high_level.md | 4 ++-- src/array/equal/mod.rs | 2 +- src/array/mod.rs | 8 +------- src/array/struct_/mod.rs | 1 - src/io/ipc/mod.rs | 3 +-- src/io/ipc/write/file_async.rs | 3 +-- src/io/ipc/write/stream_async.rs | 3 +-- src/io/json_integration/write/array.rs | 4 +--- src/io/parquet/read/deserialize/mod.rs | 2 +- src/io/parquet/read/statistics/map.rs | 2 +- src/io/parquet/write/sink.rs | 1 - tests/it/array/mod.rs | 2 +- 15 files changed, 17 insertions(+), 30 deletions(-) diff --git a/arrow-pyarrow-integration-testing/src/c_stream.rs b/arrow-pyarrow-integration-testing/src/c_stream.rs index 7a9d08b8332..8998f4812ea 100644 --- a/arrow-pyarrow-integration-testing/src/c_stream.rs +++ b/arrow-pyarrow-integration-testing/src/c_stream.rs @@ -34,9 +34,10 @@ pub fn from_rust_iterator(py: Python) -> PyResult { let array = Int32Array::from(&[Some(2), None, Some(1), None]); let array = StructArray::from_data( DataType::Struct(vec![Field::new("a", array.data_type().clone(), true)]), - vec![Box::new(array)], + vec![array.boxed()], None, - ); + ) + .boxed(); // and a field with its datatype let field = Field::new("a", array.data_type().clone(), true); diff --git a/examples/cow.rs b/examples/cow.rs index c3ae476f91f..e0bac6d3702 100644 --- a/examples/cow.rs +++ b/examples/cow.rs @@ -5,7 +5,7 @@ use arrow2::{ }; // this function will clone-on-write the array and apply `f` to its values -fn cow_apply(array: &mut Box, f: F) { +fn cow_apply(array: &mut dyn Array, f: F) { // 1. downcast the array to its concrete type let array = array .as_any_mut() @@ -33,7 +33,7 @@ fn main() { let mut array = PrimitiveArray::from_vec(vec![1i32, 2]).boxed(); // we can apply a transformation to its values without allocating a new array as follows: - cow_apply(&mut array, |values: &mut [i32]| { + cow_apply(array.as_mut(), |values: &mut [i32]| { values.iter_mut().for_each(|x| *x *= 10) }); diff --git a/examples/parquet_read_parallel/src/main.rs b/examples/parquet_read_parallel/src/main.rs index 3b6eb243bc8..313205bbfd2 100644 --- a/examples/parquet_read_parallel/src/main.rs +++ b/examples/parquet_read_parallel/src/main.rs @@ -1,7 +1,6 @@ //! Example demonstrating how to read from parquet in parallel using rayon use std::fs::File; use std::io::BufReader; -use std::sync::Arc; use std::time::SystemTime; use log::trace; @@ -18,7 +17,7 @@ mod logger; /// # Panic /// If the iterators are empty -fn deserialize_parallel(columns: &mut [ArrayIter<'static>]) -> Result>> { +fn deserialize_parallel(columns: &mut [ArrayIter<'static>]) -> Result>> { // CPU-bounded let columns = columns .par_iter_mut() diff --git a/guide/src/high_level.md b/guide/src/high_level.md index 41684c3c432..b460e44f5c2 100644 --- a/guide/src/high_level.md +++ b/guide/src/high_level.md @@ -278,6 +278,6 @@ and operated in place. Below is a complete example of how to operate on a `Box` without extra allocations. -```rust -{{#include ../../examples/cow.rs}} +```rust,ignore +{{#include ../examples/cow.rs}} ``` diff --git a/src/array/equal/mod.rs b/src/array/equal/mod.rs index eba768e752b..737edb35e76 100644 --- a/src/array/equal/mod.rs +++ b/src/array/equal/mod.rs @@ -21,7 +21,7 @@ impl PartialEq for dyn Array + '_ { } } -impl PartialEq for Arc { +impl PartialEq for std::sync::Arc { fn eq(&self, that: &dyn Array) -> bool { equal(&**self, that) } diff --git a/src/array/mod.rs b/src/array/mod.rs index be0ca2d9f07..e004bb0e778 100644 --- a/src/array/mod.rs +++ b/src/array/mod.rs @@ -139,7 +139,7 @@ pub trait MutableArray: std::fmt::Debug + Send + Sync { // This provided implementation has an extra allocation as it first // boxes `self`, then converts the box into an `Arc`. Implementors may wish // to avoid an allocation by skipping the box completely. - fn as_arc(&mut self) -> Arc { + fn as_arc(&mut self) -> std::sync::Arc { self.as_box().into() } @@ -427,9 +427,3 @@ pub unsafe trait GenericBinaryArray: Array { /// The offsets of the array fn offsets(&self) -> &[O]; } - -// backward compatibility -use std::sync::Arc; - -/// A type def of [`Array`]. -pub type ArrayRef = Arc; diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs index 58af1fe5dd7..cb888ce8721 100644 --- a/src/array/struct_/mod.rs +++ b/src/array/struct_/mod.rs @@ -14,7 +14,6 @@ mod iterator; /// multiple [`Array`] with the same number of rows. /// # Example /// ``` -/// use std::sync::Box; /// use arrow2::array::*; /// use arrow2::datatypes::*; /// let boolean = BooleanArray::from_slice(&[false, false, true, true]).boxed(); diff --git a/src/io/ipc/mod.rs b/src/io/ipc/mod.rs index 6877a5574bd..3fa3eb01a6b 100644 --- a/src/io/ipc/mod.rs +++ b/src/io/ipc/mod.rs @@ -31,7 +31,6 @@ //! ``` //! use arrow2::io::ipc::{{read::{FileReader, read_file_metadata}}, {write::{FileWriter, WriteOptions}}}; //! # use std::fs::File; -//! # use std::sync::Arc; //! # use arrow2::datatypes::{Field, Schema, DataType}; //! # use arrow2::array::{Int32Array, Array}; //! # use arrow2::chunk::Chunk; @@ -48,7 +47,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![x_data.arced(), y_data.arced()])?; +//! let chunk = Chunk::try_new(vec![x_data.boxed(), y_data.boxed()])?; //! //! // Write the messages and finalize the stream //! for _ in 0..5 { diff --git a/src/io/ipc/write/file_async.rs b/src/io/ipc/write/file_async.rs index 3a1e5fbd87e..dfe0c0b7fc4 100644 --- a/src/io/ipc/write/file_async.rs +++ b/src/io/ipc/write/file_async.rs @@ -23,7 +23,6 @@ type WriteOutput = (usize, Option, Vec, Option); /// # Examples /// /// ``` -/// use std::sync::Arc; /// use futures::{SinkExt, TryStreamExt, io::Cursor}; /// use arrow2::array::{Array, Int32Array}; /// use arrow2::datatypes::{DataType, Field, Schema}; @@ -46,7 +45,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![values.arced()]); +/// let chunk = Chunk::new(vec![values.boxed()]); /// 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 238bc5338d0..8d156ff16ad 100644 --- a/src/io/ipc/write/stream_async.rs +++ b/src/io/ipc/write/stream_async.rs @@ -20,7 +20,6 @@ use crate::error::{Error, Result}; /// # Examples /// /// ``` -/// use std::sync::Arc; /// use futures::SinkExt; /// use arrow2::array::{Array, Int32Array}; /// use arrow2::datatypes::{DataType, Field, Schema}; @@ -41,7 +40,7 @@ use crate::error::{Error, Result}; /// /// for i in 0..3 { /// let values = Int32Array::from(&[Some(i), None]); -/// let chunk = Chunk::new(vec![values.arced()]); +/// let chunk = Chunk::new(vec![values.boxed()]); /// sink.feed(chunk.into()).await?; /// } /// sink.close().await?; diff --git a/src/io/json_integration/write/array.rs b/src/io/json_integration/write/array.rs index 0d317b9a7e4..af4871138fd 100644 --- a/src/io/json_integration/write/array.rs +++ b/src/io/json_integration/write/array.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use crate::{ array::{Array, PrimitiveArray}, chunk::Chunk, @@ -10,7 +8,7 @@ use super::super::{ArrowJsonBatch, ArrowJsonColumn}; /// Serializes a [`Chunk`] to [`ArrowJsonBatch`]. pub fn serialize_chunk( - columns: &Chunk>, + columns: &Chunk>, names: &[A], ) -> ArrowJsonBatch { let count = columns.len(); diff --git a/src/io/parquet/read/deserialize/mod.rs b/src/io/parquet/read/deserialize/mod.rs index a8012b1c588..9e68206c14a 100644 --- a/src/io/parquet/read/deserialize/mod.rs +++ b/src/io/parquet/read/deserialize/mod.rs @@ -317,7 +317,7 @@ where inner, None, ); - Ok((nested, array.arced())) + Ok((nested, array.boxed())) })) } other => { diff --git a/src/io/parquet/read/statistics/map.rs b/src/io/parquet/read/statistics/map.rs index ddc09c9c518..71ef8154dd0 100644 --- a/src/io/parquet/read/statistics/map.rs +++ b/src/io/parquet/read/statistics/map.rs @@ -41,7 +41,7 @@ impl MutableArray for DynMutableMapArray { Box::new(MapArray::new( self.data_type.clone(), vec![0, self.inner.len() as i32].into(), - self.inner.as_arc(), + self.inner.as_box(), None, )) } diff --git a/src/io/parquet/write/sink.rs b/src/io/parquet/write/sink.rs index 2e8c88621bb..160ac81d7fe 100644 --- a/src/io/parquet/write/sink.rs +++ b/src/io/parquet/write/sink.rs @@ -18,7 +18,6 @@ use super::{Encoding, SchemaDescriptor, WriteOptions}; /// # Examples /// /// ``` -/// use std::sync::Box; /// use futures::SinkExt; /// use arrow2::array::{Array, Int32Array}; /// use arrow2::datatypes::{DataType, Field, Schema}; diff --git a/tests/it/array/mod.rs b/tests/it/array/mod.rs index dfa9329fffb..ef14b993d25 100644 --- a/tests/it/array/mod.rs +++ b/tests/it/array/mod.rs @@ -102,5 +102,5 @@ fn test_with_validity() { // check that `PartialEq` can be derived #[derive(PartialEq)] struct A { - array: std::sync::Arc, + array: Box, }