diff --git a/bench-vortex/src/lib.rs b/bench-vortex/src/lib.rs index 5e104cea65..607a743181 100644 --- a/bench-vortex/src/lib.rs +++ b/bench-vortex/src/lib.rs @@ -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; @@ -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; @@ -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(); diff --git a/pyvortex/src/encode.rs b/pyvortex/src/encode.rs index 728ed34707..740a590ea6 100644 --- a/pyvortex/src/encode.rs +++ b/pyvortex/src/encode.rs @@ -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; diff --git a/pyvortex/src/vortex_arrow.rs b/pyvortex/src/vortex_arrow.rs index 3cef6dcfad..2bfe0be15f 100644 --- a/pyvortex/src/vortex_arrow.rs +++ b/pyvortex/src/vortex_arrow.rs @@ -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>(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")); } diff --git a/vortex-alp/src/array.rs b/vortex-alp/src/array.rs index 3cc24d75a7..cc234d4340 100644 --- a/vortex-alp/src/array.rs +++ b/vortex-alp/src/array.rs @@ -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()))?; diff --git a/vortex-alp/src/serde.rs b/vortex-alp/src/serde.rs index 34334a1f13..1d1831c7df 100644 --- a/vortex-alp/src/serde.rs +++ b/vortex-alp/src/serde.rs @@ -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!( diff --git a/vortex-array/src/array/bool/mod.rs b/vortex-array/src/array/bool/mod.rs index ca4e5bfd7f..76b5826383 100644 --- a/vortex-array/src/array/bool/mod.rs +++ b/vortex-array/src/array/bool/mod.rs @@ -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}; @@ -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); @@ -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] diff --git a/vortex-array/src/array/bool/serde.rs b/vortex-array/src/array/bool/serde.rs index e4da7f1d2a..1028fc7ebf 100644 --- a/vortex-array/src/array/bool/serde.rs +++ b/vortex-array/src/array/bool/serde.rs @@ -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!( diff --git a/vortex-array/src/array/chunked/mod.rs b/vortex-array/src/array/chunked/mod.rs index ac569c611a..b6769b3636 100644 --- a/vortex-array/src/array/chunked/mod.rs +++ b/vortex-array/src/array/chunked/mod.rs @@ -163,12 +163,6 @@ impl FromIterator 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() { @@ -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; @@ -224,7 +218,7 @@ mod test { } fn assert_equal_slices(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()); diff --git a/vortex-array/src/array/chunked/serde.rs b/vortex-array/src/array/chunked/serde.rs index d080f30333..a069e62c36 100644 --- a/vortex-array/src/array/chunked/serde.rs +++ b/vortex-array/src/array/chunked/serde.rs @@ -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!( diff --git a/vortex-array/src/array/composite/array.rs b/vortex-array/src/array/composite/array.rs index 5cf11d7586..305b4cdf88 100644 --- a/vortex-array/src/array/composite/array.rs +++ b/vortex-array/src/array/composite/array.rs @@ -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()))?; diff --git a/vortex-array/src/array/constant/mod.rs b/vortex-array/src/array/constant/mod.rs index ac21c5d233..403dfe6a1d 100644 --- a/vortex-array/src/array/constant/mod.rs +++ b/vortex-array/src/array/constant/mod.rs @@ -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()) diff --git a/vortex-array/src/array/constant/serde.rs b/vortex-array/src/array/constant/serde.rs index 36e7413a62..d20d128872 100644 --- a/vortex-array/src/array/constant/serde.rs +++ b/vortex-array/src/array/constant/serde.rs @@ -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()); diff --git a/vortex-array/src/array/mod.rs b/vortex-array/src/array/mod.rs index 29c131ff39..3df3535392 100644 --- a/vortex-array/src/array/mod.rs +++ b/vortex-array/src/array/mod.rs @@ -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; @@ -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 { () => { @@ -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 { @@ -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); diff --git a/vortex-array/src/array/primitive/compute/cast.rs b/vortex-array/src/array/primitive/compute/cast.rs index cafabf966c..499895f6ab 100644 --- a/vortex-array/src/array/primitive/compute/cast.rs +++ b/vortex-array/src/array/primitive/compute/cast.rs @@ -41,7 +41,7 @@ fn cast(array: &PrimitiveArray) -> VortexResult> { #[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; diff --git a/vortex-array/src/array/primitive/compute/fill.rs b/vortex-array/src/array/primitive/compute/fill.rs index 9e63e733fa..46982776ae 100644 --- a/vortex-array/src/array/primitive/compute/fill.rs +++ b/vortex-array/src/array/primitive/compute/fill.rs @@ -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; @@ -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::(), vec![0, 8, 8, 10, 10]); assert!(filled_primitive.validity().is_none()); @@ -63,7 +63,7 @@ mod test { #[test] fn all_none() { let arr = PrimitiveArray::from_iter(vec![Option::::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::(), vec![0, 0, 0, 0, 0]); assert!(filled_primitive.validity().is_none()); @@ -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::(), vec![8, 10, 12, 14, 16]); assert!(filled_primitive.validity().is_none()); diff --git a/vortex-array/src/array/primitive/mod.rs b/vortex-array/src/array/primitive/mod.rs index e40ca041ca..6be46f49cf 100644 --- a/vortex-array/src/array/primitive/mod.rs +++ b/vortex-array/src/array/primitive/mod.rs @@ -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}; @@ -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 ArrayAccessor for PrimitiveArray { fn value(&self, index: usize) -> Option { if self.is_valid(index) { @@ -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] @@ -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)); } } diff --git a/vortex-array/src/array/primitive/serde.rs b/vortex-array/src/array/primitive/serde.rs index 25221321a1..a27ac88e1e 100644 --- a/vortex-array/src/array/primitive/serde.rs +++ b/vortex-array/src/array/primitive/serde.rs @@ -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::(), read_arr.as_primitive().buffer().typed_data::() diff --git a/vortex-array/src/array/sparse/mod.rs b/vortex-array/src/array/sparse/mod.rs index bdeeb76050..1270ed103b 100644 --- a/vortex-array/src/array/sparse/mod.rs +++ b/vortex-array/src/array/sparse/mod.rs @@ -144,12 +144,6 @@ impl Array for SparseArray { impl StatsCompute for SparseArray {} -impl<'arr> AsRef<(dyn Array + 'arr)> for SparseArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for SparseArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.property("offset", self.indices_offset())?; @@ -188,7 +182,7 @@ mod test { use crate::array::sparse::SparseArray; use crate::array::Array; - use crate::arrow::dtypes::IntoArray; + use crate::array::IntoArray; use crate::compute::flatten::flatten_primitive; use crate::compute::scalar_at::scalar_at; use crate::error::VortexError; @@ -213,7 +207,7 @@ mod test { #[test] pub fn iter() { assert_sparse_array( - sparse_array().as_ref(), + &sparse_array(), &[ None, None, @@ -253,11 +247,11 @@ mod test { #[test] pub fn test_scalar_at() { assert_eq!( - usize::try_from(scalar_at(sparse_array().as_ref(), 2).unwrap()).unwrap(), + usize::try_from(scalar_at(&sparse_array(), 2).unwrap()).unwrap(), 100 ); assert_eq!( - scalar_at(sparse_array().as_ref(), 10).err().unwrap(), + scalar_at(&sparse_array(), 10).err().unwrap(), VortexError::OutOfBounds(10, 0, 10) ); } diff --git a/vortex-array/src/array/sparse/serde.rs b/vortex-array/src/array/sparse/serde.rs index 1af34c07cb..b8c4890f3e 100644 --- a/vortex-array/src/array/sparse/serde.rs +++ b/vortex-array/src/array/sparse/serde.rs @@ -35,7 +35,7 @@ mod test { use crate::array::primitive::PrimitiveArray; use crate::array::sparse::SparseArray; use crate::array::Array; - use crate::arrow::dtypes::IntoArray; + use crate::array::IntoArray; use crate::serde::test::roundtrip_array; #[test] @@ -46,7 +46,7 @@ mod test { 100, ); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); assert_eq!( arr.indices().as_primitive().buffer().typed_data::(), diff --git a/vortex-array/src/array/struct_/mod.rs b/vortex-array/src/array/struct_/mod.rs index 3c40ccb41d..2cb29f6154 100644 --- a/vortex-array/src/array/struct_/mod.rs +++ b/vortex-array/src/array/struct_/mod.rs @@ -112,12 +112,6 @@ impl Array for StructArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for StructArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl StatsCompute for StructArray {} #[derive(Debug)] diff --git a/vortex-array/src/array/struct_/serde.rs b/vortex-array/src/array/struct_/serde.rs index cdd9b6e9ac..357bf6bb45 100644 --- a/vortex-array/src/array/struct_/serde.rs +++ b/vortex-array/src/array/struct_/serde.rs @@ -37,7 +37,7 @@ mod test { use crate::array::primitive::PrimitiveArray; use crate::array::struct_::StructArray; use crate::array::Array; - use crate::arrow::dtypes::IntoArray; + use crate::array::IntoArray; use crate::serde::test::roundtrip_array; #[test] @@ -53,7 +53,7 @@ mod test { ], ); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); assert_eq!( arr.fields()[0].as_primitive().buffer().typed_data::(), diff --git a/vortex-array/src/array/varbin/mod.rs b/vortex-array/src/array/varbin/mod.rs index 0e27683f2e..71596ae5ed 100644 --- a/vortex-array/src/array/varbin/mod.rs +++ b/vortex-array/src/array/varbin/mod.rs @@ -265,12 +265,6 @@ impl Array for VarBinArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for VarBinArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - #[derive(Debug)] pub struct VarBinEncoding; @@ -379,9 +373,9 @@ mod test { pub fn test_scalar_at() { let binary_arr = binary_array(); assert_eq!(binary_arr.len(), 2); - assert_eq!(scalar_at(binary_arr.as_ref(), 0), Ok("hello world".into())); + assert_eq!(scalar_at(&binary_arr, 0), Ok("hello world".into())); assert_eq!( - scalar_at(binary_arr.as_ref(), 1), + scalar_at(&binary_arr, 1), Ok("hello world this is a long string".into()) ) } @@ -390,7 +384,7 @@ mod test { pub fn slice() { let binary_arr = binary_array().slice(1, 2).unwrap(); assert_eq!( - scalar_at(binary_arr.as_ref(), 0), + scalar_at(&binary_arr, 0), Ok("hello world this is a long string".into()) ); } diff --git a/vortex-array/src/array/varbin/serde.rs b/vortex-array/src/array/varbin/serde.rs index e465f31f88..14c274666f 100644 --- a/vortex-array/src/array/varbin/serde.rs +++ b/vortex-array/src/array/varbin/serde.rs @@ -44,7 +44,7 @@ mod test { DType::Utf8(Nullability::NonNullable), ); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); assert_eq!( arr.offsets().as_primitive().buffer().typed_data::(), diff --git a/vortex-array/src/array/varbinview/mod.rs b/vortex-array/src/array/varbinview/mod.rs index dadb4dea27..22cc177fde 100644 --- a/vortex-array/src/array/varbinview/mod.rs +++ b/vortex-array/src/array/varbinview/mod.rs @@ -255,12 +255,6 @@ impl Array for VarBinViewArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for VarBinViewArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - #[derive(Debug)] pub struct VarBinViewEncoding; @@ -329,9 +323,9 @@ mod test { pub fn varbin_view() { let binary_arr = binary_array(); assert_eq!(binary_arr.len(), 2); - assert_eq!(scalar_at(binary_arr.as_ref(), 0), Ok("hello world".into())); + assert_eq!(scalar_at(&binary_arr, 0), Ok("hello world".into())); assert_eq!( - scalar_at(binary_arr.as_ref(), 1), + scalar_at(&binary_arr, 1), Ok("hello world this is a long string".into()) ) } @@ -340,7 +334,7 @@ mod test { pub fn slice() { let binary_arr = binary_array().slice(1, 2).unwrap(); assert_eq!( - scalar_at(binary_arr.as_ref(), 0), + scalar_at(&binary_arr, 0), Ok("hello world this is a long string".into()) ); } diff --git a/vortex-array/src/array/varbinview/serde.rs b/vortex-array/src/array/varbinview/serde.rs index a0eb78649f..8e7707b5d7 100644 --- a/vortex-array/src/array/varbinview/serde.rs +++ b/vortex-array/src/array/varbinview/serde.rs @@ -74,7 +74,7 @@ mod test { #[test] fn roundtrip() { let arr = binary_array(); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); assert_eq!( arr.views().as_primitive().buffer().typed_data::(), diff --git a/vortex-array/src/arrow/dtypes.rs b/vortex-array/src/arrow/dtypes.rs index b795a3a963..91e0bffded 100644 --- a/vortex-array/src/arrow/dtypes.rs +++ b/vortex-array/src/arrow/dtypes.rs @@ -1,50 +1,15 @@ use std::sync::Arc; -use arrow_array::RecordBatch; use arrow_schema::TimeUnit as ArrowTimeUnit; use arrow_schema::{DataType, Field, SchemaRef}; use itertools::Itertools; use vortex_schema::{DType, FloatWidth, IntWidth, Nullability}; -use crate::array::struct_::StructArray; -use crate::array::{Array, ArrayRef}; use crate::arrow::FromArrowType; -use crate::compute::cast::cast; use crate::datetime::{LocalDateTimeExtension, TimeUnit}; -use crate::encode::FromArrowArray; use crate::error::{VortexError, VortexResult}; use crate::ptype::PType; -// FIXME(ngates): move this somewhere? -pub trait IntoArray { - fn into_array(self) -> ArrayRef; -} - -impl IntoArray for &RecordBatch { - fn into_array(self) -> ArrayRef { - StructArray::new( - self.schema() - .fields() - .iter() - .map(|f| f.name()) - .map(|s| s.to_owned()) - .map(Arc::new) - .collect(), - self.columns() - .iter() - .zip(self.schema().fields()) - .map(|(array, field)| { - // The dtype of the child arrays infer their nullability from the array itself. - // In case the schema says something different, we cast into the schema's dtype. - let vortex_array = ArrayRef::from_arrow(array.clone(), field.is_nullable()); - cast(&vortex_array, &DType::from_arrow(field.as_ref())).unwrap() - }) - .collect(), - ) - .into_array() - } -} - impl TryFrom<&DataType> for PType { type Error = VortexError; diff --git a/vortex-array/src/arrow/mod.rs b/vortex-array/src/arrow/mod.rs index bf9a621991..0931622c66 100644 --- a/vortex-array/src/arrow/mod.rs +++ b/vortex-array/src/arrow/mod.rs @@ -1,4 +1,5 @@ pub mod dtypes; +mod recordbatch; pub mod wrappers; pub trait FromArrowType: Sized { diff --git a/vortex-array/src/arrow/recordbatch.rs b/vortex-array/src/arrow/recordbatch.rs new file mode 100644 index 0000000000..d4b3333666 --- /dev/null +++ b/vortex-array/src/arrow/recordbatch.rs @@ -0,0 +1,33 @@ +use crate::array::struct_::StructArray; +use crate::array::{Array, ArrayRef, IntoArray}; +use crate::arrow::FromArrowType; +use crate::compute::cast::cast; +use crate::encode::FromArrowArray; +use arrow_array::RecordBatch; +use std::sync::Arc; +use vortex_schema::DType; + +impl IntoArray for &RecordBatch { + fn into_array(self) -> ArrayRef { + StructArray::new( + self.schema() + .fields() + .iter() + .map(|f| f.name()) + .map(|s| s.to_owned()) + .map(Arc::new) + .collect(), + self.columns() + .iter() + .zip(self.schema().fields()) + .map(|(array, field)| { + // The dtype of the child arrays infer their nullability from the array itself. + // In case the schema says something different, we cast into the schema's dtype. + let vortex_array = ArrayRef::from_arrow(array.clone(), field.is_nullable()); + cast(&vortex_array, &DType::from_arrow(field.as_ref())).unwrap() + }) + .collect(), + ) + .into_array() + } +} diff --git a/vortex-array/src/compress.rs b/vortex-array/src/compress.rs index 0956f784b2..10177e7fc8 100644 --- a/vortex-array/src/compress.rs +++ b/vortex-array/src/compress.rs @@ -156,12 +156,7 @@ impl CompressCtx { // We don't take a reference to self to force the caller to think about whether to use // an auxilliary ctx. - pub fn compress>( - self, - arr: T, - like: Option<&ArrayRef>, - ) -> VortexResult { - let arr = arr.as_ref(); + pub fn compress(self, arr: &dyn Array, like: Option<&ArrayRef>) -> VortexResult { if arr.is_empty() { return Ok(arr.to_array()); } @@ -186,8 +181,8 @@ impl CompressCtx { self.compress_array(arr) } - fn compress_array>(&self, arr: T) -> VortexResult { - match ArrayKind::from(arr.as_ref()) { + fn compress_array(&self, arr: &dyn Array) -> VortexResult { + match ArrayKind::from(arr) { ArrayKind::Chunked(chunked) => { // For chunked arrays, we compress each chunk individually let compressed_chunks: VortexResult> = chunked @@ -212,8 +207,8 @@ impl CompressCtx { } _ => { // Otherwise, we run sampled compression over pluggable encodings - let sampled = sampled_compression(&arr, self)?; - Ok(sampled.unwrap_or_else(|| arr.as_ref().to_array())) + let sampled = sampled_compression(arr, self)?; + Ok(sampled.unwrap_or_else(|| arr.to_array())) } } } @@ -225,12 +220,8 @@ impl Default for CompressCtx { } } -pub fn sampled_compression>( - array: &T, - ctx: &CompressCtx, -) -> VortexResult> { +pub fn sampled_compression(array: &dyn Array, ctx: &CompressCtx) -> VortexResult> { // First, we try constant compression and shortcut any sampling. - let array = array.as_ref(); if !array.is_empty() && array .stats() diff --git a/vortex-array/src/compute/cast.rs b/vortex-array/src/compute/cast.rs index 843fd9ca67..672ed2d1de 100644 --- a/vortex-array/src/compute/cast.rs +++ b/vortex-array/src/compute/cast.rs @@ -6,8 +6,7 @@ pub trait CastFn { fn cast(&self, dtype: &DType) -> VortexResult; } -pub fn cast>(array: T, dtype: &DType) -> VortexResult { - let array = array.as_ref(); +pub fn cast(array: &dyn Array, dtype: &DType) -> VortexResult { if array.dtype() == dtype { return Ok(array.to_array()); } diff --git a/vortex-array/src/encode.rs b/vortex-array/src/encode.rs index a17fd6f7d1..0ac53b2172 100644 --- a/vortex-array/src/encode.rs +++ b/vortex-array/src/encode.rs @@ -28,8 +28,8 @@ use crate::array::constant::ConstantArray; use crate::array::primitive::PrimitiveArray; use crate::array::struct_::StructArray; use crate::array::varbin::VarBinArray; +use crate::array::IntoArray; use crate::array::{Array, ArrayRef}; -use crate::arrow::dtypes::IntoArray; use crate::datetime::{LocalDateTime, LocalDateTimeArray}; use crate::ptype::PType; use crate::scalar::NullScalar; @@ -186,7 +186,7 @@ impl FromArrowArray for ArrayRef { DataType::Binary => ArrayRef::from_arrow(array.as_binary::(), nullable), DataType::LargeBinary => ArrayRef::from_arrow(array.as_binary::(), nullable), DataType::Struct(_) => ArrayRef::from_arrow(array.as_struct(), nullable), - DataType::Null => ArrayRef::from_arrow(as_null_array(array.as_ref()), nullable), + DataType::Null => ArrayRef::from_arrow(as_null_array(&array), nullable), DataType::Timestamp(u, _) => match u { TimeUnit::Second => { ArrayRef::from_arrow(array.as_primitive::(), nullable) diff --git a/vortex-array/src/formatter.rs b/vortex-array/src/formatter.rs index f3a20709f6..2952f1fd80 100644 --- a/vortex-array/src/formatter.rs +++ b/vortex-array/src/formatter.rs @@ -101,7 +101,7 @@ impl<'a, 'b: 'a> ArrayFormatter<'a, 'b> { #[cfg(test)] mod test { use crate::array::ArrayRef; - use crate::arrow::dtypes::IntoArray; + use crate::array::IntoArray; use crate::formatter::display_tree; #[test] @@ -116,6 +116,6 @@ mod test { #[test] fn tree_display_primitive() { let arr: ArrayRef = (0..100).collect::>().into_array(); - assert_eq!(display_tree(arr.as_ref()), "root: vortex.primitive(signed_int(32), len=100) nbytes=400 B (100.00%)\n values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]...\n validity: None\n") + assert_eq!(display_tree(&arr), "root: vortex.primitive(signed_int(32), len=100) nbytes=400 B (100.00%)\n values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]...\n validity: None\n") } } diff --git a/vortex-datetime/src/compress.rs b/vortex-datetime/src/compress.rs index f49f6b50cd..93dea2debf 100644 --- a/vortex-datetime/src/compress.rs +++ b/vortex-datetime/src/compress.rs @@ -74,12 +74,10 @@ fn compress_localdatetime( Ok(DateTimeArray::new( ctx.named("days") .compress(&PrimitiveArray::from(days), like.map(|l| l.days()))?, - ctx.named("seconds").compress( - PrimitiveArray::from(seconds).as_ref(), - like.map(|l| l.seconds()), - )?, + ctx.named("seconds") + .compress(&PrimitiveArray::from(seconds), like.map(|l| l.seconds()))?, ctx.named("subsecond").compress( - PrimitiveArray::from(subsecond).as_ref(), + &PrimitiveArray::from(subsecond), like.map(|l| l.subsecond()), )?, underlying.validity().cloned(), diff --git a/vortex-datetime/src/datetime.rs b/vortex-datetime/src/datetime.rs index efbf67947f..679cd428be 100644 --- a/vortex-datetime/src/datetime.rs +++ b/vortex-datetime/src/datetime.rs @@ -125,12 +125,6 @@ impl StatsCompute for DateTimeArray {} impl ArrayCompute for DateTimeArray {} -impl<'arr> AsRef<(dyn Array + 'arr)> for DateTimeArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for DateTimeArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.child("days", self.days())?; diff --git a/vortex-dict/src/compress.rs b/vortex-dict/src/compress.rs index 0a6c9162da..84ce7977b0 100644 --- a/vortex-dict/src/compress.rs +++ b/vortex-dict/src/compress.rs @@ -60,10 +60,10 @@ impl EncodingCompression for DictEncoding { ( ctx.auxiliary("codes") .excluding(&DictEncoding::ID) - .compress(codes, dict_like.map(|dict| dict.codes()))?, + .compress(&codes, dict_like.map(|dict| dict.codes()))?, ctx.named("values") .excluding(&DictEncoding::ID) - .compress(dict, dict_like.map(|dict| dict.dict()))?, + .compress(&dict, dict_like.map(|dict| dict.dict()))?, ) } ArrayKind::VarBin(vb) => { @@ -71,10 +71,10 @@ impl EncodingCompression for DictEncoding { ( ctx.auxiliary("codes") .excluding(&DictEncoding::ID) - .compress(codes, dict_like.map(|dict| dict.codes()))?, + .compress(&codes, dict_like.map(|dict| dict.codes()))?, ctx.named("values") .excluding(&DictEncoding::ID) - .compress(dict, dict_like.map(|dict| dict.dict()))?, + .compress(&dict, dict_like.map(|dict| dict.dict()))?, ) } @@ -233,8 +233,8 @@ mod test { codes.buffer().typed_data::(), &[0, 0, 1, 2, 2, 1, 2, 1] ); - assert_eq!(scalar_at(values.as_ref(), 0), Ok(1.into())); - assert_eq!(scalar_at(values.as_ref(), 2), Ok(3.into())); + assert_eq!(scalar_at(&values, 0), Ok(1.into())); + assert_eq!(scalar_at(&values, 2), Ok(3.into())); } #[test] diff --git a/vortex-dict/src/dict.rs b/vortex-dict/src/dict.rs index 6b25949cee..70337dbae1 100644 --- a/vortex-dict/src/dict.rs +++ b/vortex-dict/src/dict.rs @@ -81,12 +81,6 @@ impl Array for DictArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for DictArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for DictArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.child("values", self.dict())?; diff --git a/vortex-dict/src/serde.rs b/vortex-dict/src/serde.rs index 3d84947127..ebba3dd3f8 100644 --- a/vortex-dict/src/serde.rs +++ b/vortex-dict/src/serde.rs @@ -25,8 +25,8 @@ impl EncodingSerde for DictEncoding { #[cfg(test)] mod test { use vortex::array::downcast::DowncastArrayBuiltin; + use vortex::array::IntoArray; use vortex::array::{Array, ArrayRef}; - use vortex::arrow::dtypes::IntoArray; use vortex::error::VortexResult; use vortex::serde::{ReadCtx, WriteCtx}; @@ -48,7 +48,7 @@ mod test { vec![0u8, 0, 1, 2, 3].into_array(), vec![-7i64, -13, 17, 23].into_array(), ); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); assert_eq!( arr.codes().as_primitive().buffer().typed_data::(), diff --git a/vortex-fastlanes/src/bitpacking/compress.rs b/vortex-fastlanes/src/bitpacking/compress.rs index 5672573167..101b884830 100644 --- a/vortex-fastlanes/src/bitpacking/compress.rs +++ b/vortex-fastlanes/src/bitpacking/compress.rs @@ -5,8 +5,8 @@ use fastlanez_sys::TryBitPack; use vortex::array::downcast::DowncastArrayBuiltin; use vortex::array::primitive::PrimitiveArray; use vortex::array::sparse::SparseArray; +use vortex::array::IntoArray; use vortex::array::{Array, ArrayRef}; -use vortex::arrow::dtypes::IntoArray; use vortex::compress::{CompressConfig, CompressCtx, EncodingCompression}; use vortex::compute::cast::cast; use vortex::compute::flatten::flatten_primitive; diff --git a/vortex-fastlanes/src/bitpacking/mod.rs b/vortex-fastlanes/src/bitpacking/mod.rs index 284e7e2985..143601ded6 100644 --- a/vortex-fastlanes/src/bitpacking/mod.rs +++ b/vortex-fastlanes/src/bitpacking/mod.rs @@ -123,12 +123,6 @@ impl Array for BitPackedArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for BitPackedArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for BitPackedArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.property("packed", format!("u{}", self.bit_width()))?; diff --git a/vortex-fastlanes/src/for/compress.rs b/vortex-fastlanes/src/for/compress.rs index 4a548edc88..68222e88b5 100644 --- a/vortex-fastlanes/src/for/compress.rs +++ b/vortex-fastlanes/src/for/compress.rs @@ -58,7 +58,7 @@ impl EncodingCompression for FoREncoding { // NOTE(ngates): we don't invoke next_level here since we know bit-packing is always // worth trying. let compressed_child = ctx.named("for").excluding(&FoREncoding::ID).compress( - child, + &child, like.map(|l| l.as_any().downcast_ref::().unwrap().encoded()), )?; let reference = parray.stats().get(&Stat::Min).unwrap(); diff --git a/vortex-fastlanes/src/for/mod.rs b/vortex-fastlanes/src/for/mod.rs index b1ad1c5ce3..e5f1779920 100644 --- a/vortex-fastlanes/src/for/mod.rs +++ b/vortex-fastlanes/src/for/mod.rs @@ -97,12 +97,6 @@ impl Array for FoRArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for FoRArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for FoRArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.property("reference", self.reference())?; diff --git a/vortex-fastlanes/src/for/serde.rs b/vortex-fastlanes/src/for/serde.rs index 76fc710285..ba8e96b0be 100644 --- a/vortex-fastlanes/src/for/serde.rs +++ b/vortex-fastlanes/src/for/serde.rs @@ -26,8 +26,8 @@ impl EncodingSerde for FoREncoding { #[cfg(test)] mod test { + use vortex::array::IntoArray; use vortex::array::{Array, ArrayRef}; - use vortex::arrow::dtypes::IntoArray; use vortex::error::VortexResult; use vortex::scalar::Scalar; use vortex::serde::{ReadCtx, WriteCtx}; @@ -51,6 +51,6 @@ mod test { 2, ) .unwrap(); - roundtrip_array(arr.as_ref()).unwrap(); + roundtrip_array(&arr).unwrap(); } } diff --git a/vortex-ree/src/compress.rs b/vortex-ree/src/compress.rs index 87b1017258..5f40b01698 100644 --- a/vortex-ree/src/compress.rs +++ b/vortex-ree/src/compress.rs @@ -46,11 +46,11 @@ impl EncodingCompression for REEEncoding { let (ends, values) = ree_encode(primitive_array); let compressed_ends = ctx .auxiliary("ends") - .compress(ends, ree_like.map(|ree| ree.ends()))?; + .compress(&ends, ree_like.map(|ree| ree.ends()))?; let compressed_values = ctx .named("values") .excluding(&REEEncoding::ID) - .compress(values, ree_like.map(|ree| ree.values()))?; + .compress(&values, ree_like.map(|ree| ree.values()))?; Ok(REEArray::new( compressed_ends, @@ -142,7 +142,7 @@ mod test { use vortex::array::downcast::DowncastArrayBuiltin; use vortex::array::primitive::PrimitiveArray; use vortex::array::Array; - use vortex::arrow::dtypes::IntoArray; + use vortex::array::IntoArray; use crate::compress::{ree_decode, ree_encode}; use crate::REEArray; diff --git a/vortex-ree/src/ree.rs b/vortex-ree/src/ree.rs index 1b0b3ea891..ce98bae435 100644 --- a/vortex-ree/src/ree.rs +++ b/vortex-ree/src/ree.rs @@ -166,12 +166,6 @@ impl Array for REEArray { impl StatsCompute for REEArray {} -impl<'arr> AsRef<(dyn Array + 'arr)> for REEArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - #[derive(Debug)] pub struct REEEncoding; @@ -203,7 +197,7 @@ impl ArrayDisplay for REEArray { #[cfg(test)] mod test { use vortex::array::Array; - use vortex::arrow::dtypes::IntoArray; + use vortex::array::IntoArray; use vortex::compute::flatten::flatten_primitive; use vortex::compute::scalar_at::scalar_at; use vortex_schema::{DType, IntWidth, Nullability, Signedness}; @@ -227,10 +221,10 @@ mod test { // 0, 1 => 1 // 2, 3, 4 => 2 // 5, 6, 7, 8, 9 => 3 - assert_eq!(scalar_at(arr.as_ref(), 0).unwrap().try_into(), Ok(1)); - assert_eq!(scalar_at(arr.as_ref(), 2).unwrap().try_into(), Ok(2)); - assert_eq!(scalar_at(arr.as_ref(), 5).unwrap().try_into(), Ok(3)); - assert_eq!(scalar_at(arr.as_ref(), 9).unwrap().try_into(), Ok(3)); + assert_eq!(scalar_at(&arr, 0).unwrap().try_into(), Ok(1)); + assert_eq!(scalar_at(&arr, 2).unwrap().try_into(), Ok(2)); + assert_eq!(scalar_at(&arr, 5).unwrap().try_into(), Ok(3)); + assert_eq!(scalar_at(&arr, 9).unwrap().try_into(), Ok(3)); } #[test] @@ -250,7 +244,7 @@ mod test { assert_eq!(arr.len(), 5); assert_eq!( - flatten_primitive(arr.as_ref()).unwrap().typed_data::(), + flatten_primitive(&arr).unwrap().typed_data::(), vec![2, 2, 3, 3, 3] ); } @@ -264,7 +258,7 @@ mod test { 10, ); assert_eq!( - flatten_primitive(arr.as_ref()).unwrap().typed_data::(), + flatten_primitive(&arr).unwrap().typed_data::(), vec![1, 1, 2, 2, 2, 3, 3, 3, 3, 3] ); } diff --git a/vortex-ree/src/serde.rs b/vortex-ree/src/serde.rs index 6ed10c3ae9..739dfc840d 100644 --- a/vortex-ree/src/serde.rs +++ b/vortex-ree/src/serde.rs @@ -36,8 +36,8 @@ impl EncodingSerde for REEEncoding { mod test { use vortex::array::downcast::DowncastArrayBuiltin; + use vortex::array::IntoArray; use vortex::array::{Array, ArrayRef}; - use vortex::arrow::dtypes::IntoArray; use vortex::error::VortexResult; use vortex::serde::{ReadCtx, WriteCtx}; @@ -61,7 +61,7 @@ mod test { None, 49, ); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); let read_ree = read_arr.as_ree(); assert_eq!( diff --git a/vortex-roaring/src/boolean/mod.rs b/vortex-roaring/src/boolean/mod.rs index f888a1906d..50ba74ca7b 100644 --- a/vortex-roaring/src/boolean/mod.rs +++ b/vortex-roaring/src/boolean/mod.rs @@ -100,12 +100,6 @@ impl Array for RoaringBoolArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for RoaringBoolArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for RoaringBoolArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.property("bitmap", format!("{:?}", self.bitmap())) @@ -162,10 +156,10 @@ mod test { let truthy: Scalar = true.into(); let falsy: Scalar = false.into(); - assert_eq!(scalar_at(array.as_ref(), 0)?, truthy); - assert_eq!(scalar_at(array.as_ref(), 1)?, falsy); - assert_eq!(scalar_at(array.as_ref(), 2)?, truthy); - assert_eq!(scalar_at(array.as_ref(), 3)?, truthy); + assert_eq!(scalar_at(&array, 0)?, truthy); + assert_eq!(scalar_at(&array, 1)?, falsy); + assert_eq!(scalar_at(&array, 2)?, truthy); + assert_eq!(scalar_at(&array, 3)?, truthy); Ok(()) } diff --git a/vortex-roaring/src/boolean/serde.rs b/vortex-roaring/src/boolean/serde.rs index 60adf6fe2e..e7ff174025 100644 --- a/vortex-roaring/src/boolean/serde.rs +++ b/vortex-roaring/src/boolean/serde.rs @@ -42,7 +42,7 @@ mod test { #[test] fn roundtrip() { let arr = RoaringBoolArray::new(Bitmap::from_range(245..63000), 65536); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); let read_roaring = read_arr.as_roaring_bool(); assert_eq!(arr.bitmap(), read_roaring.bitmap()); diff --git a/vortex-roaring/src/integer/mod.rs b/vortex-roaring/src/integer/mod.rs index 0b2280e69b..a4e82ec4a9 100644 --- a/vortex-roaring/src/integer/mod.rs +++ b/vortex-roaring/src/integer/mod.rs @@ -102,12 +102,6 @@ impl Array for RoaringIntArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for RoaringIntArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for RoaringIntArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.property("bitmap", format!("{:?}", self.bitmap())) @@ -146,10 +140,10 @@ mod test { #[test] pub fn test_scalar_at() -> VortexResult<()> { let ints = PrimitiveArray::from(vec![2u32, 12, 22, 32]); - let array = RoaringIntArray::encode(ints.as_ref())?; + let array = RoaringIntArray::encode(&ints)?; - assert_eq!(scalar_at(array.as_ref(), 0), Ok(2u32.into())); - assert_eq!(scalar_at(array.as_ref(), 1), Ok(12u32.into())); + assert_eq!(scalar_at(&array, 0), Ok(2u32.into())); + assert_eq!(scalar_at(&array, 1), Ok(12u32.into())); Ok(()) } diff --git a/vortex-roaring/src/integer/serde.rs b/vortex-roaring/src/integer/serde.rs index aae2758a45..008937e1c3 100644 --- a/vortex-roaring/src/integer/serde.rs +++ b/vortex-roaring/src/integer/serde.rs @@ -47,7 +47,7 @@ mod test { #[test] fn roundtrip() { let arr = RoaringIntArray::new(Bitmap::from_range(245..63000), PType::U32); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); let read_roaring = read_arr.as_roaring_int(); assert_eq!(arr.ptype(), read_roaring.ptype()); assert_eq!(arr.bitmap(), read_roaring.bitmap()); diff --git a/vortex-zigzag/src/serde.rs b/vortex-zigzag/src/serde.rs index b98247f192..9769f06537 100644 --- a/vortex-zigzag/src/serde.rs +++ b/vortex-zigzag/src/serde.rs @@ -45,7 +45,7 @@ mod test { #[test] fn roundtrip() { let arr = zigzag_encode(&PrimitiveArray::from(vec![-7i64, -13, 17, 23])).unwrap(); - let read_arr = roundtrip_array(arr.as_ref()).unwrap(); + let read_arr = roundtrip_array(&arr).unwrap(); let read_zigzag = read_arr.as_zigzag(); assert_eq!( diff --git a/vortex-zigzag/src/zigzag.rs b/vortex-zigzag/src/zigzag.rs index a60c48f65f..9507429b45 100644 --- a/vortex-zigzag/src/zigzag.rs +++ b/vortex-zigzag/src/zigzag.rs @@ -91,12 +91,6 @@ impl Array for ZigZagArray { } } -impl<'arr> AsRef<(dyn Array + 'arr)> for ZigZagArray { - fn as_ref(&self) -> &(dyn Array + 'arr) { - self - } -} - impl ArrayDisplay for ZigZagArray { fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result { f.child("zigzag", self.encoded())