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

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jun 8, 2022
1 parent 715fe71 commit 6818e10
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 30 deletions.
5 changes: 3 additions & 2 deletions arrow-pyarrow-integration-testing/src/c_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ pub fn from_rust_iterator(py: Python) -> PyResult<PyObject> {
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);

Expand Down
4 changes: 2 additions & 2 deletions examples/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use arrow2::{
};

// this function will clone-on-write the array and apply `f` to its values
fn cow_apply<T: NativeType, F: Fn(&mut [T])>(array: &mut Box<dyn Array>, f: F) {
fn cow_apply<T: NativeType, F: Fn(&mut [T])>(array: &mut dyn Array, f: F) {
// 1. downcast the array to its concrete type
let array = array
.as_any_mut()
Expand Down Expand Up @@ -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)
});

Expand Down
3 changes: 1 addition & 2 deletions examples/parquet_read_parallel/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,7 +17,7 @@ mod logger;

/// # Panic
/// If the iterators are empty
fn deserialize_parallel(columns: &mut [ArrayIter<'static>]) -> Result<Chunk<Arc<dyn Array>>> {
fn deserialize_parallel(columns: &mut [ArrayIter<'static>]) -> Result<Chunk<Box<dyn Array>>> {
// CPU-bounded
let columns = columns
.par_iter_mut()
Expand Down
4 changes: 2 additions & 2 deletions guide/src/high_level.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,6 @@ and operated in place.
Below is a complete example of how to operate on a `Box<dyn Array>` without
extra allocations.

```rust
{{#include ../../examples/cow.rs}}
```rust,ignore
{{#include ../examples/cow.rs}}
```
2 changes: 1 addition & 1 deletion src/array/equal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl PartialEq for dyn Array + '_ {
}
}

impl PartialEq<dyn Array> for Arc<dyn Array + '_> {
impl PartialEq<dyn Array> for std::sync::Arc<dyn Array + '_> {
fn eq(&self, that: &dyn Array) -> bool {
equal(&**self, that)
}
Expand Down
8 changes: 1 addition & 7 deletions src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Array> {
fn as_arc(&mut self) -> std::sync::Arc<dyn Array> {
self.as_box().into()
}

Expand Down Expand Up @@ -427,9 +427,3 @@ pub unsafe trait GenericBinaryArray<O: Offset>: 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<dyn Array>;
1 change: 0 additions & 1 deletion src/array/struct_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/io/ipc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/io/ipc/write/file_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type WriteOutput<W> = (usize, Option<Block>, Vec<Block>, Option<W>);
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use futures::{SinkExt, TryStreamExt, io::Cursor};
/// use arrow2::array::{Array, Int32Array};
/// use arrow2::datatypes::{DataType, Field, Schema};
Expand All @@ -46,7 +45,7 @@ type WriteOutput<W> = (usize, Option<Block>, Vec<Block>, Option<W>);
/// // 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?;
Expand Down
3 changes: 1 addition & 2 deletions src/io/ipc/write/stream_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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?;
Expand Down
4 changes: 1 addition & 3 deletions src/io/json_integration/write/array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use crate::{
array::{Array, PrimitiveArray},
chunk::Chunk,
Expand All @@ -10,7 +8,7 @@ use super::super::{ArrowJsonBatch, ArrowJsonColumn};

/// Serializes a [`Chunk`] to [`ArrowJsonBatch`].
pub fn serialize_chunk<A: ToString>(
columns: &Chunk<Arc<dyn Array>>,
columns: &Chunk<Box<dyn Array>>,
names: &[A],
) -> ArrowJsonBatch {
let count = columns.len();
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/read/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ where
inner,
None,
);
Ok((nested, array.arced()))
Ok((nested, array.boxed()))
}))
}
other => {
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/read/statistics/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
))
}
Expand Down
1 change: 0 additions & 1 deletion src/io/parquet/write/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion tests/it/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ fn test_with_validity() {
// check that `PartialEq` can be derived
#[derive(PartialEq)]
struct A {
array: std::sync::Arc<dyn Array>,
array: Box<dyn Array>,
}

0 comments on commit 6818e10

Please sign in to comment.