Skip to content

Commit

Permalink
Remove as_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Mar 22, 2024
1 parent 911e3b5 commit 23c0d42
Show file tree
Hide file tree
Showing 51 changed files with 141 additions and 264 deletions.
6 changes: 3 additions & 3 deletions bench-vortex/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use arrow_array::RecordBatchReader;
use std::collections::HashSet;
use std::fs::{create_dir_all, File};
use std::path::{Path, PathBuf};
use std::sync::Arc;

use arrow_array::RecordBatchReader;
use itertools::Itertools;
use log::{info, warn};
use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder;
Expand All @@ -19,8 +19,8 @@ use vortex::array::sparse::SparseEncoding;
use vortex::array::struct_::StructEncoding;
use vortex::array::varbin::VarBinEncoding;
use vortex::array::varbinview::VarBinViewEncoding;
use vortex::array::IntoArray;
use vortex::array::{Array, ArrayRef, Encoding};
use vortex::arrow::dtypes::IntoArray;
use vortex::arrow::FromArrowType;
use vortex::compress::{CompressConfig, CompressCtx};
use vortex::formatter::display_tree;
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn compress_taxi_data() -> ArrayRef {
.map(|batch| batch.into_array())
.map(|array| {
uncompressed_size += array.nbytes();
ctx.clone().compress(array.as_ref(), None).unwrap()
ctx.clone().compress(&array, None).unwrap()
})
.collect_vec();

Expand Down
2 changes: 1 addition & 1 deletion pyvortex/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use pyo3::prelude::*;
use crate::array::PyArray;
use crate::vortex_arrow::map_arrow_err;
use vortex::array::chunked::ChunkedArray;
use vortex::array::IntoArray;
use vortex::array::{Array, ArrayRef};
use vortex::arrow::dtypes::IntoArray;
use vortex::arrow::FromArrowType;
use vortex::encode::FromArrowArray;
use vortex_schema::DType;
Expand Down
4 changes: 2 additions & 2 deletions pyvortex/src/vortex_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub fn map_arrow_err(error: ArrowError) -> PyErr {
PyValueError::new_err(error.to_string())
}

pub fn export_array<'py, T: AsRef<dyn Array>>(py: Python<'py>, array: &T) -> PyResult<&'py PyAny> {
pub fn export_array<'py>(py: Python<'py>, array: &dyn Array) -> PyResult<&'py PyAny> {
// NOTE(ngates): for struct arrays, we could also return a RecordBatchStreamReader.
// NOTE(robert): Return RecordBatchStreamReader always?
let chunks = as_arrow_chunks(array.as_ref()).unwrap();
let chunks = as_arrow_chunks(array).unwrap();
if chunks.is_empty() {
return Err(PyValueError::new_err("No chunks in array"));
}
Expand Down
6 changes: 0 additions & 6 deletions vortex-alp/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ impl Array for ALPArray {
}
}

impl<'arr> AsRef<(dyn Array + 'arr)> for ALPArray {
fn as_ref(&self) -> &(dyn Array + 'arr) {
self
}
}

impl ArrayDisplay for ALPArray {
fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result {
f.property("exponents", format!("{:?}", self.exponents()))?;
Expand Down
2 changes: 1 addition & 1 deletion vortex-alp/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod test {
0.33f64,
]))
.unwrap();
let read_arr = roundtrip_array(arr.as_ref()).unwrap();
let read_arr = roundtrip_array(&arr).unwrap();

let read_alp = read_arr.as_alp();
assert_eq!(
Expand Down
14 changes: 4 additions & 10 deletions vortex-array/src/array/bool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::{Arc, RwLock};
use arrow_buffer::buffer::BooleanBuffer;
use linkme::distributed_slice;

use crate::arrow::dtypes::IntoArray;
use crate::array::IntoArray;
use crate::impl_array;
use vortex_schema::{DType, Nullability};

Expand Down Expand Up @@ -148,12 +148,6 @@ impl Encoding for BoolEncoding {
}
}

impl<'a> AsRef<(dyn Array + 'a)> for BoolArray {
fn as_ref(&self) -> &(dyn Array + 'a) {
self
}
}

impl ArrayDisplay for BoolArray {
fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result {
let true_count = self.stats().get_or_compute_or(0usize, &Stat::TrueCount);
Expand Down Expand Up @@ -215,9 +209,9 @@ mod test {
.slice(1, 4)
.unwrap();
assert_eq!(arr.len(), 3);
assert_eq!(scalar_at(arr.as_ref(), 0).unwrap().try_into(), Ok(true));
assert_eq!(scalar_at(arr.as_ref(), 1).unwrap().try_into(), Ok(false));
assert_eq!(scalar_at(arr.as_ref(), 2).unwrap().try_into(), Ok(false));
assert_eq!(scalar_at(&arr, 0).unwrap().try_into(), Ok(true));
assert_eq!(scalar_at(&arr, 1).unwrap().try_into(), Ok(false));
assert_eq!(scalar_at(&arr, 2).unwrap().try_into(), Ok(false));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/bool/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod test {
#[test]
fn roundtrip() {
let arr = BoolArray::from_iter(vec![Some(false), None, Some(true), Some(false)]);
let read_arr = roundtrip_array(arr.as_ref()).unwrap();
let read_arr = roundtrip_array(&arr).unwrap();

assert_eq!(arr.buffer().values(), read_arr.as_bool().buffer().values());
assert_eq!(
Expand Down
10 changes: 2 additions & 8 deletions vortex-array/src/array/chunked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,6 @@ impl FromIterator<ArrayRef> for ChunkedArray {
}
}

impl<'arr> AsRef<(dyn Array + 'arr)> for ChunkedArray {
fn as_ref(&self) -> &(dyn Array + 'arr) {
self
}
}

impl ArrayDisplay for ChunkedArray {
fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result {
for (i, c) in self.chunks().iter().enumerate() {
Expand Down Expand Up @@ -204,7 +198,7 @@ mod test {
use vortex_schema::{DType, IntWidth, Nullability, Signedness};

use crate::array::chunked::ChunkedArray;
use crate::arrow::dtypes::IntoArray;
use crate::array::IntoArray;
use crate::compute::flatten::{flatten, flatten_primitive, FlattenedArray};
use crate::ptype::NativePType;

Expand All @@ -224,7 +218,7 @@ mod test {
}

fn assert_equal_slices<T: NativePType>(arr: ArrayRef, slice: &[T]) {
let FlattenedArray::Chunked(chunked) = flatten(arr.as_ref()).unwrap() else {
let FlattenedArray::Chunked(chunked) = flatten(&arr).unwrap() else {
unreachable!()
};
let mut values = Vec::with_capacity(arr.len());
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/chunked/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod test {
DType::Int(IntWidth::_32, Signedness::Signed, Nullability::Nullable),
);

let read_arr = roundtrip_array(arr.as_ref()).unwrap();
let read_arr = roundtrip_array(&arr).unwrap();

for (i, chunk) in arr.chunks().iter().enumerate() {
assert_eq!(
Expand Down
6 changes: 0 additions & 6 deletions vortex-array/src/array/composite/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ impl Array for CompositeArray {

impl StatsCompute for CompositeArray {}

impl<'arr> AsRef<(dyn Array + 'arr)> for CompositeArray {
fn as_ref(&self) -> &(dyn Array + 'arr) {
self
}
}

impl ArrayDisplay for CompositeArray {
fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result {
f.property("metadata", format!("{:#?}", self.metadata().as_slice()))?;
Expand Down
6 changes: 0 additions & 6 deletions vortex-array/src/array/constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ impl Array for ConstantArray {
}
}

impl<'arr> AsRef<(dyn Array + 'arr)> for ConstantArray {
fn as_ref(&self) -> &(dyn Array + 'arr) {
self
}
}

impl ArrayDisplay for ConstantArray {
fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result {
f.property("scalar", self.scalar())
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/constant/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod test {
#[test]
fn roundtrip() {
let arr = ConstantArray::new(PrimitiveScalar::some(PScalar::I32(42)).into(), 100);
let read_arr = roundtrip_array(arr.as_ref()).unwrap();
let read_arr = roundtrip_array(&arr).unwrap();

assert_eq!(arr.scalar(), read_arr.as_constant().scalar());
assert_eq!(arr.len(), read_arr.len());
Expand Down
30 changes: 14 additions & 16 deletions vortex-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ use crate::array::struct_::{StructArray, StructEncoding};
use crate::array::varbin::{VarBinArray, VarBinEncoding};
use crate::array::varbinview::{VarBinViewArray, VarBinViewEncoding};
use crate::compress::EncodingCompression;
use crate::compute::as_arrow::AsArrowArray;
use crate::compute::as_contiguous::AsContiguousFn;
use crate::compute::cast::CastFn;
use crate::compute::fill::FillForwardFn;
use crate::compute::flatten::FlattenFn;
use crate::compute::patch::PatchFn;
use crate::compute::scalar_at::ScalarAtFn;
use crate::compute::search_sorted::SearchSortedFn;
use crate::compute::take::TakeFn;
use crate::compute::ArrayCompute;
use crate::error::{VortexError, VortexResult};
use crate::formatter::{ArrayDisplay, ArrayFormatter};
use crate::serde::{ArraySerde, EncodingSerde};
use crate::stats::Stats;

Expand Down Expand Up @@ -70,6 +80,10 @@ pub trait Array: ArrayCompute + ArrayDisplay + Debug + Send + Sync {
}
}

pub trait IntoArray {
fn into_array(self) -> ArrayRef;
}

#[macro_export]
macro_rules! impl_array {
() => {
Expand Down Expand Up @@ -99,16 +113,6 @@ macro_rules! impl_array {
};
}

use crate::compute::as_arrow::AsArrowArray;
use crate::compute::as_contiguous::AsContiguousFn;
use crate::compute::cast::CastFn;
use crate::compute::fill::FillForwardFn;
use crate::compute::flatten::FlattenFn;
use crate::compute::patch::PatchFn;
use crate::compute::scalar_at::ScalarAtFn;
use crate::compute::search_sorted::SearchSortedFn;
use crate::compute::take::TakeFn;
use crate::formatter::{ArrayDisplay, ArrayFormatter};
pub use impl_array;

impl ArrayCompute for ArrayRef {
Expand Down Expand Up @@ -243,12 +247,6 @@ pub fn check_validity_buffer(validity: Option<&ArrayRef>, expected_len: usize) -
Ok(())
}

impl<'a> AsRef<(dyn Array + 'a)> for dyn Array {
fn as_ref(&self) -> &(dyn Array + 'a) {
self
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct EncodingId(&'static str);

Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/primitive/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn cast<T: NativePType>(array: &PrimitiveArray) -> VortexResult<Vec<T>> {
#[cfg(test)]
mod test {
use crate::array::downcast::DowncastArrayBuiltin;
use crate::arrow::dtypes::IntoArray;
use crate::array::IntoArray;
use crate::compute;
use crate::error::VortexError;
use crate::ptype::PType;
Expand Down
8 changes: 4 additions & 4 deletions vortex-array/src/array/primitive/compute/fill.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use num_traits::Zero;

use crate::array::primitive::PrimitiveArray;
use crate::array::IntoArray;
use crate::array::{Array, ArrayRef};
use crate::arrow::dtypes::IntoArray;
use crate::compute::fill::FillForwardFn;
use crate::compute::flatten::flatten_bool;
use crate::error::VortexResult;
Expand Down Expand Up @@ -54,7 +54,7 @@ mod test {
#[test]
fn leading_none() {
let arr = PrimitiveArray::from_iter(vec![None, Some(8u8), None, Some(10), None]);
let filled = compute::fill::fill_forward(arr.as_ref()).unwrap();
let filled = compute::fill::fill_forward(&arr).unwrap();
let filled_primitive = filled.as_primitive();
assert_eq!(filled_primitive.typed_data::<u8>(), vec![0, 8, 8, 10, 10]);
assert!(filled_primitive.validity().is_none());
Expand All @@ -63,7 +63,7 @@ mod test {
#[test]
fn all_none() {
let arr = PrimitiveArray::from_iter(vec![Option::<u8>::None, None, None, None, None]);
let filled = compute::fill::fill_forward(arr.as_ref()).unwrap();
let filled = compute::fill::fill_forward(&arr).unwrap();
let filled_primitive = filled.as_primitive();
assert_eq!(filled_primitive.typed_data::<u8>(), vec![0, 0, 0, 0, 0]);
assert!(filled_primitive.validity().is_none());
Expand All @@ -75,7 +75,7 @@ mod test {
vec![8u8, 10u8, 12u8, 14u8, 16u8],
Some(BoolArray::from(vec![true, true, true, true, true]).into_array()),
);
let filled = compute::fill::fill_forward(arr.as_ref()).unwrap();
let filled = compute::fill::fill_forward(&arr).unwrap();
let filled_primitive = filled.as_primitive();
assert_eq!(filled_primitive.typed_data::<u8>(), vec![8, 10, 12, 14, 16]);
assert!(filled_primitive.validity().is_none());
Expand Down
20 changes: 7 additions & 13 deletions vortex-array/src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use linkme::distributed_slice;
use vortex_schema::DType;

use crate::array::bool::BoolArray;
use crate::array::IntoArray;
use crate::array::{
check_slice_bounds, check_validity_buffer, Array, ArrayRef, Encoding, EncodingId, EncodingRef,
ENCODINGS,
};
use crate::arrow::dtypes::IntoArray;
use crate::compute::scalar_at::scalar_at;
use crate::error::VortexResult;
use crate::formatter::{ArrayDisplay, ArrayFormatter};
Expand Down Expand Up @@ -200,12 +200,6 @@ impl Array for PrimitiveArray {
}
}

impl<'arr> AsRef<(dyn Array + 'arr)> for PrimitiveArray {
fn as_ref(&self) -> &(dyn Array + 'arr) {
self
}
}

impl<T: NativePType> ArrayAccessor<T> for PrimitiveArray {
fn value(&self, index: usize) -> Option<T> {
if self.is_valid(index) {
Expand Down Expand Up @@ -313,9 +307,9 @@ mod test {
);

// Ensure we can fetch the scalar at the given index.
assert_eq!(scalar_at(arr.as_ref(), 0).unwrap().try_into(), Ok(1));
assert_eq!(scalar_at(arr.as_ref(), 1).unwrap().try_into(), Ok(2));
assert_eq!(scalar_at(arr.as_ref(), 2).unwrap().try_into(), Ok(3));
assert_eq!(scalar_at(&arr, 0).unwrap().try_into(), Ok(1));
assert_eq!(scalar_at(&arr, 1).unwrap().try_into(), Ok(2));
assert_eq!(scalar_at(&arr, 2).unwrap().try_into(), Ok(3));
}

#[test]
Expand All @@ -324,8 +318,8 @@ mod test {
.slice(1, 4)
.unwrap();
assert_eq!(arr.len(), 3);
assert_eq!(scalar_at(arr.as_ref(), 0).unwrap().try_into(), Ok(2));
assert_eq!(scalar_at(arr.as_ref(), 1).unwrap().try_into(), Ok(3));
assert_eq!(scalar_at(arr.as_ref(), 2).unwrap().try_into(), Ok(4));
assert_eq!(scalar_at(&arr, 0).unwrap().try_into(), Ok(2));
assert_eq!(scalar_at(&arr, 1).unwrap().try_into(), Ok(3));
assert_eq!(scalar_at(&arr, 2).unwrap().try_into(), Ok(4));
}
}
2 changes: 1 addition & 1 deletion vortex-array/src/array/primitive/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod test {
#[test]
fn roundtrip() {
let arr = PrimitiveArray::from_iter(vec![Some(0), None, Some(2), Some(42)]);
let read_arr = roundtrip_array(arr.as_ref()).unwrap();
let read_arr = roundtrip_array(&arr).unwrap();
assert_eq!(
arr.buffer().typed_data::<i32>(),
read_arr.as_primitive().buffer().typed_data::<i32>()
Expand Down
Loading

0 comments on commit 23c0d42

Please sign in to comment.