diff --git a/bench-vortex/benches/compress_benchmark.rs b/bench-vortex/benches/compress_benchmark.rs index cc4fa0a242..05d947cafb 100644 --- a/bench-vortex/benches/compress_benchmark.rs +++ b/bench-vortex/benches/compress_benchmark.rs @@ -14,7 +14,7 @@ use vortex::array::varbin::VarBinArray; use vortex::array::{Array, ArrayRef}; use vortex::compress::CompressCtx; use vortex::dtype::DType; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex_bench::enumerate_arrays; @@ -57,7 +57,7 @@ fn enc_compress(c: &mut Criterion) { let chunks = reader .map(|batch_result| batch_result.map_err(VortexError::from)) .map(|batch| batch.map(|b| b.into())) - .collect::>>() + .collect::>>() .unwrap(); let chunked = ChunkedArray::new(chunks, dtype); println!( diff --git a/bench-vortex/src/lib.rs b/bench-vortex/src/lib.rs index edb2b3fea6..78e1da74a2 100644 --- a/bench-vortex/src/lib.rs +++ b/bench-vortex/src/lib.rs @@ -37,7 +37,7 @@ mod test { use vortex::array::{Array, ArrayRef}; use vortex::compress::CompressCtx; use vortex::dtype::DType; - use vortex::error::{VortexError, EncResult}; + use vortex::error::{VortexError, VortexResult}; pub fn download_taxi_data() -> &'static Path { let download_path = Path::new("../../pyspiral/bench/.data/https-d37ci6vzurychx-cloudfront-net-trip-data-yellow-tripdata-2023-11.parquet"); @@ -81,7 +81,7 @@ mod test { let chunks = reader .map(|batch_result| batch_result.map_err(VortexError::from)) .map(|batch| batch.map(|b| b.into())) - .collect::>>() + .collect::>>() .unwrap(); let chunked = ChunkedArray::new(chunks, dtype); println!( diff --git a/pyvortex/src/array.rs b/pyvortex/src/array.rs index cc08c03cb8..e04d6060ea 100644 --- a/pyvortex/src/array.rs +++ b/pyvortex/src/array.rs @@ -16,12 +16,14 @@ use vortex_alp::{ALPArray, ALP_ENCODING}; use vortex_dict::{DictArray, DICT_ENCODING}; use vortex_ffor::{FFORArray, FFOR_ENCODING}; use vortex_ree::{REEArray, REE_ENCODING}; -use vortex_roaring::{RoaringBoolArray, RoaringIntArray, ROARING_BOOL_ENCODING, ROARING_INT_ENCODING}; +use vortex_roaring::{ + RoaringBoolArray, RoaringIntArray, ROARING_BOOL_ENCODING, ROARING_INT_ENCODING, +}; use vortex_zigzag::{ZigZagArray, ZIGZAG_ENCODING}; use crate::dtype::PyDType; -use crate::vortex_arrow; use crate::error::PyVortexError; +use crate::vortex_arrow; #[pyclass(name = "Array", module = "vortex", sequence, subclass)] pub struct PyArray { diff --git a/pyvortex/src/dtype.rs b/pyvortex/src/dtype.rs index 569812cdbd..14f76243fc 100644 --- a/pyvortex/src/dtype.rs +++ b/pyvortex/src/dtype.rs @@ -1,8 +1,8 @@ use arrow::datatypes::DataType; use arrow::pyarrow::FromPyArrow; -use vortex::arrow::convert::TryIntoDType; use pyo3::types::PyType; use pyo3::{pyclass, pymethods, Py, PyAny, PyResult, Python}; +use vortex::arrow::convert::TryIntoDType; use vortex::dtype::DType; diff --git a/pyvortex/src/encode.rs b/pyvortex/src/encode.rs index 1e3c21e45d..2604cec8dd 100644 --- a/pyvortex/src/encode.rs +++ b/pyvortex/src/encode.rs @@ -12,8 +12,8 @@ use vortex::arrow::convert::TryIntoDType; use vortex::dtype::DType; use crate::array::PyArray; -use crate::vortex_arrow::map_arrow_err; use crate::error::PyVortexError; +use crate::vortex_arrow::map_arrow_err; /// The main entry point for creating enc arrays from other Python objects. /// diff --git a/pyvortex/src/lib.rs b/pyvortex/src/lib.rs index ca95cfc054..c57674f93a 100644 --- a/pyvortex/src/lib.rs +++ b/pyvortex/src/lib.rs @@ -10,10 +10,10 @@ use crate::compress::PyCompressConfig; mod array; mod compress; mod dtype; -mod vortex_arrow; mod encode; mod error; mod serde; +mod vortex_arrow; /// A Python module implemented in Rust. #[pymodule] diff --git a/vortex-alp/src/alp.rs b/vortex-alp/src/alp.rs index 111ed78eeb..86e32fceda 100644 --- a/vortex-alp/src/alp.rs +++ b/vortex-alp/src/alp.rs @@ -6,7 +6,7 @@ pub use codecz::alp::ALPExponents; use vortex::array::{Array, ArrayKind, ArrayRef, ArrowIterator, Encoding, EncodingId, EncodingRef}; use vortex::compress::EncodingCompression; use vortex::dtype::{DType, FloatWidth, IntWidth, Signedness}; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::scalar::{NullableScalar, Scalar}; use vortex::serde::{ArraySerde, EncodingSerde}; @@ -32,7 +32,7 @@ impl ALPArray { encoded: ArrayRef, exponents: ALPExponents, patches: Option, - ) -> EncResult { + ) -> VortexResult { let dtype = match encoded.dtype() { d @ DType::Int(width, Signedness::Signed, nullability) => match width { IntWidth::_32 => DType::Float(32.into(), *nullability), @@ -50,7 +50,7 @@ impl ALPArray { }) } - pub fn encode(array: &dyn Array) -> EncResult { + pub fn encode(array: &dyn Array) -> VortexResult { match ArrayKind::from(array) { ArrayKind::Primitive(p) => Ok(alp_encode(p).boxed()), _ => Err(VortexError::InvalidEncoding(array.encoding().id().clone())), @@ -106,7 +106,7 @@ impl Array for ALPArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { if let Some(patch) = self .patches() .and_then(|p| p.scalar_at(index).ok()) @@ -141,7 +141,7 @@ impl Array for ALPArray { todo!() } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { Ok(Self::try_new( self.encoded().slice(start, stop)?, self.exponents(), diff --git a/vortex-alp/src/lib.rs b/vortex-alp/src/lib.rs index bd69090987..6f0fe3ae42 100644 --- a/vortex-alp/src/lib.rs +++ b/vortex-alp/src/lib.rs @@ -1,6 +1,6 @@ pub use alp::*; -use vortex::array::{EncodingRef, ENCODINGS}; use linkme::distributed_slice; +use vortex::array::{EncodingRef, ENCODINGS}; mod alp; mod compress; diff --git a/vortex-dict/src/dict.rs b/vortex-dict/src/dict.rs index 691e8f2ad5..0a96198833 100644 --- a/vortex-dict/src/dict.rs +++ b/vortex-dict/src/dict.rs @@ -6,7 +6,7 @@ use vortex::array::{ }; use vortex::compress::EncodingCompression; use vortex::dtype::{DType, Signedness}; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::scalar::Scalar; use vortex::serde::{ArraySerde, EncodingSerde}; @@ -24,7 +24,7 @@ impl DictArray { Self::try_new(codes, dict).unwrap() } - pub fn try_new(codes: ArrayRef, dict: ArrayRef) -> EncResult { + pub fn try_new(codes: ArrayRef, dict: ArrayRef) -> VortexResult { if !matches!(codes.dtype(), DType::Int(_, Signedness::Unsigned, _)) { return Err(VortexError::InvalidDType(codes.dtype().clone())); } @@ -75,7 +75,7 @@ impl Array for DictArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; let dict_index: usize = self.codes().scalar_at(index)?.try_into()?; self.dict().scalar_at(dict_index) @@ -86,7 +86,7 @@ impl Array for DictArray { } // TODO(robert): Add function to trim the dictionary - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; Ok(Self::new(self.codes().slice(start, stop)?, self.dict.clone()).boxed()) } diff --git a/vortex-dict/src/lib.rs b/vortex-dict/src/lib.rs index 376c4e2314..afef63b7da 100644 --- a/vortex-dict/src/lib.rs +++ b/vortex-dict/src/lib.rs @@ -1,5 +1,5 @@ -use vortex::array::{EncodingRef, ENCODINGS}; use linkme::distributed_slice; +use vortex::array::{EncodingRef, ENCODINGS}; pub use compress::*; pub use dict::*; diff --git a/vortex-ffor/src/ffor.rs b/vortex-ffor/src/ffor.rs index 247d8134ca..613c945bb1 100644 --- a/vortex-ffor/src/ffor.rs +++ b/vortex-ffor/src/ffor.rs @@ -8,7 +8,7 @@ use vortex::array::{ }; use vortex::compress::EncodingCompression; use vortex::dtype::DType; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::match_each_integer_ptype; use vortex::scalar::{NullableScalar, Scalar}; @@ -47,7 +47,7 @@ impl FFORArray { min_val: Box, num_bits: u8, len: usize, - ) -> EncResult { + ) -> VortexResult { let validity = validity.filter(|v| !v.is_empty()); check_validity_buffer(validity.as_ref())?; @@ -70,7 +70,7 @@ impl FFORArray { }) } - pub fn encode(array: &dyn Array) -> EncResult { + pub fn encode(array: &dyn Array) -> VortexResult { match ArrayKind::from(array) { ArrayKind::Primitive(p) => Ok(ffor_encode(p).boxed()), _ => Err(VortexError::InvalidEncoding(array.encoding().id().clone())), @@ -145,7 +145,7 @@ impl Array for FFORArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { if !self.is_valid(index) { return Ok(NullableScalar::none(self.dtype().clone()).boxed()); } @@ -185,7 +185,7 @@ impl Array for FFORArray { todo!() } - fn slice(&self, _start: usize, _stop: usize) -> EncResult { + fn slice(&self, _start: usize, _stop: usize) -> VortexResult { unimplemented!("FFoRArray::slice") } diff --git a/vortex-ffor/src/lib.rs b/vortex-ffor/src/lib.rs index b7c2db0c05..66482fbe64 100644 --- a/vortex-ffor/src/lib.rs +++ b/vortex-ffor/src/lib.rs @@ -1,6 +1,6 @@ -use vortex::array::{EncodingRef, ENCODINGS}; pub use ffor::*; use linkme::distributed_slice; +use vortex::array::{EncodingRef, ENCODINGS}; mod compress; mod downcast; diff --git a/vortex-ree/src/lib.rs b/vortex-ree/src/lib.rs index c2b6f182db..7fecbf9c23 100644 --- a/vortex-ree/src/lib.rs +++ b/vortex-ree/src/lib.rs @@ -1,5 +1,5 @@ -use vortex::array::{EncodingRef, ENCODINGS}; use linkme::distributed_slice; +use vortex::array::{EncodingRef, ENCODINGS}; pub use ree::*; diff --git a/vortex-ree/src/ree.rs b/vortex-ree/src/ree.rs index c68f5c3af5..2150a89f76 100644 --- a/vortex-ree/src/ree.rs +++ b/vortex-ree/src/ree.rs @@ -18,7 +18,7 @@ use vortex::compress::EncodingCompression; use vortex::compute; use vortex::compute::search_sorted::SearchSortedSide; use vortex::dtype::{DType, Nullability, Signedness}; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::ptype::NativePType; use vortex::scalar::Scalar; @@ -52,7 +52,7 @@ impl REEArray { values: ArrayRef, validity: Option, length: usize, - ) -> EncResult { + ) -> VortexResult { check_validity_buffer(validity.as_ref())?; if !matches!( @@ -82,7 +82,7 @@ impl REEArray { }) } - pub fn find_physical_index(&self, index: usize) -> EncResult { + pub fn find_physical_index(&self, index: usize) -> VortexResult { compute::search_sorted::search_sorted_usize( self.ends(), index + self.offset, @@ -90,7 +90,7 @@ impl REEArray { ) } - pub fn encode(array: &dyn Array) -> EncResult { + pub fn encode(array: &dyn Array) -> VortexResult { match ArrayKind::from(array) { ArrayKind::Primitive(p) => { let (ends, values) = ree_encode(p); @@ -155,7 +155,7 @@ impl Array for REEArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; self.values.scalar_at(self.find_physical_index(index)?) } @@ -185,7 +185,7 @@ impl Array for REEArray { }) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; let slice_begin = self.find_physical_index(start)?; let slice_end = self.find_physical_index(stop)?; @@ -314,8 +314,8 @@ fn run_ends_logical_length>(ends: &T) -> usize { mod test { use arrow::array::cast::AsArray; use arrow::array::types::Int32Type; - use vortex::array::Array; use itertools::Itertools; + use vortex::array::Array; use crate::REEArray; use vortex::dtype::{DType, IntWidth, Nullability, Signedness}; diff --git a/vortex-roaring/src/boolean/mod.rs b/vortex-roaring/src/boolean/mod.rs index 5b4320a527..49856c882c 100644 --- a/vortex-roaring/src/boolean/mod.rs +++ b/vortex-roaring/src/boolean/mod.rs @@ -11,7 +11,7 @@ use vortex::array::{ use vortex::compress::EncodingCompression; use vortex::dtype::DType; use vortex::dtype::Nullability::NonNullable; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::scalar::Scalar; use vortex::serde::{ArraySerde, EncodingSerde}; @@ -41,7 +41,7 @@ impl RoaringBoolArray { &self.bitmap } - pub fn encode(array: &dyn Array) -> EncResult { + pub fn encode(array: &dyn Array) -> VortexResult { match ArrayKind::from(array) { ArrayKind::Bool(p) => Ok(roaring_encode(p)), _ => Err(VortexError::InvalidEncoding(array.encoding().id().clone())), @@ -84,7 +84,7 @@ impl Array for RoaringBoolArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; if self.bitmap.contains(index as u32) { @@ -98,7 +98,7 @@ impl Array for RoaringBoolArray { todo!() } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; let slice_bitmap = Bitmap::from_range(start as u32..stop as u32); @@ -163,13 +163,13 @@ impl Encoding for RoaringBoolEncoding { mod test { use vortex::array::bool::BoolArray; use vortex::array::Array; - use vortex::error::EncResult; + use vortex::error::VortexResult; use vortex::scalar::Scalar; use crate::RoaringBoolArray; #[test] - pub fn iter() -> EncResult<()> { + pub fn iter() -> VortexResult<()> { let bool: &dyn Array = &BoolArray::from(vec![true, false, true, true]); let array = RoaringBoolArray::encode(bool)?; @@ -180,7 +180,7 @@ mod test { } #[test] - pub fn scalar_at() -> EncResult<()> { + pub fn scalar_at() -> VortexResult<()> { let bool: &dyn Array = &BoolArray::from(vec![true, false, true, true]); let array = RoaringBoolArray::encode(bool)?; diff --git a/vortex-roaring/src/boolean/stats.rs b/vortex-roaring/src/boolean/stats.rs index 02d83041e9..9c7a141a0b 100644 --- a/vortex-roaring/src/boolean/stats.rs +++ b/vortex-roaring/src/boolean/stats.rs @@ -37,13 +37,13 @@ impl StatsCompute for RoaringBoolArray { mod test { use vortex::array::bool::BoolArray; use vortex::array::Array; - use vortex::error::EncResult; + use vortex::error::VortexResult; use vortex::stats::Stat::*; use crate::RoaringBoolArray; #[test] - pub fn stats_all_true() -> EncResult<()> { + pub fn stats_all_true() -> VortexResult<()> { let bool: &dyn Array = &BoolArray::from(vec![true, true]); let array = RoaringBoolArray::encode(bool)?; @@ -65,7 +65,7 @@ mod test { } #[test] - pub fn stats_all_false() -> EncResult<()> { + pub fn stats_all_false() -> VortexResult<()> { let bool: &dyn Array = &BoolArray::from(vec![false, false]); let array = RoaringBoolArray::encode(bool)?; @@ -87,7 +87,7 @@ mod test { } #[test] - pub fn stats_mixed() -> EncResult<()> { + pub fn stats_mixed() -> VortexResult<()> { let bool: &dyn Array = &BoolArray::from(vec![false, true, true]); let array = RoaringBoolArray::encode(bool)?; diff --git a/vortex-roaring/src/integer/mod.rs b/vortex-roaring/src/integer/mod.rs index 03c6e477fc..72262dcc65 100644 --- a/vortex-roaring/src/integer/mod.rs +++ b/vortex-roaring/src/integer/mod.rs @@ -10,7 +10,7 @@ use vortex::array::{ }; use vortex::compress::EncodingCompression; use vortex::dtype::DType; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::ptype::PType; use vortex::scalar::Scalar; @@ -33,7 +33,7 @@ impl RoaringIntArray { Self::try_new(bitmap, ptype).unwrap() } - pub fn try_new(bitmap: Bitmap, ptype: PType) -> EncResult { + pub fn try_new(bitmap: Bitmap, ptype: PType) -> VortexResult { if !ptype.is_unsigned_int() { return Err(VortexError::InvalidPType(ptype)); } @@ -53,7 +53,7 @@ impl RoaringIntArray { self.ptype } - pub fn encode(array: &dyn Array) -> EncResult { + pub fn encode(array: &dyn Array) -> VortexResult { match ArrayKind::from(array) { ArrayKind::Primitive(p) => Ok(roaring_encode(p)), _ => Err(VortexError::InvalidEncoding(array.encoding().id().clone())), @@ -96,7 +96,7 @@ impl Array for RoaringIntArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; // Unwrap since we know the index is valid let bitmap_value = self.bitmap.select(index as u32).unwrap(); @@ -114,7 +114,7 @@ impl Array for RoaringIntArray { todo!() } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; todo!() } @@ -169,12 +169,12 @@ impl Encoding for RoaringIntEncoding { mod test { use vortex::array::primitive::PrimitiveArray; use vortex::array::Array; - use vortex::error::EncResult; + use vortex::error::VortexResult; use crate::RoaringIntArray; #[test] - pub fn scalar_at() -> EncResult<()> { + pub fn scalar_at() -> VortexResult<()> { let ints: &dyn Array = &PrimitiveArray::from_vec::(vec![2, 12, 22, 32]); let array = RoaringIntArray::encode(ints)?; diff --git a/vortex-roaring/src/lib.rs b/vortex-roaring/src/lib.rs index cb14601252..0e844e00c8 100644 --- a/vortex-roaring/src/lib.rs +++ b/vortex-roaring/src/lib.rs @@ -1,8 +1,8 @@ use linkme::distributed_slice; pub use boolean::*; -use vortex::array::{EncodingRef, ENCODINGS}; pub use integer::*; +use vortex::array::{EncodingRef, ENCODINGS}; mod boolean; mod downcast; diff --git a/vortex-roaring/src/serde_tests.rs b/vortex-roaring/src/serde_tests.rs index 925fdcde28..71a06a9a7a 100644 --- a/vortex-roaring/src/serde_tests.rs +++ b/vortex-roaring/src/serde_tests.rs @@ -1,8 +1,8 @@ #[cfg(test)] pub mod test { + use std::io; use vortex::array::{Array, ArrayRef}; use vortex::serde::{ReadCtx, WriteCtx}; - use std::io; pub fn roundtrip_array(array: &dyn Array) -> io::Result { let mut buf = Vec::::new(); diff --git a/vortex-zigzag/src/compress.rs b/vortex-zigzag/src/compress.rs index 250ec83157..f2e6f97aa8 100644 --- a/vortex-zigzag/src/compress.rs +++ b/vortex-zigzag/src/compress.rs @@ -5,7 +5,7 @@ use vortex::array::downcast::DowncastArrayBuiltin; use vortex::array::primitive::PrimitiveArray; use vortex::array::{Array, ArrayKind, ArrayRef}; use vortex::compress::{CompressConfig, CompressCtx, Compressor, EncodingCompression}; -use vortex::error::EncResult; +use vortex::error::VortexResult; use vortex::ptype::{NativePType, PType}; use vortex::stats::Stat; use vortex_alloc::{AlignedVec, ALIGNED_ALLOCATOR}; @@ -50,7 +50,7 @@ fn zigzag_compressor(array: &dyn Array, like: Option<&dyn Array>, ctx: CompressC .boxed() } -pub fn zigzag_encode(parray: &PrimitiveArray) -> EncResult { +pub fn zigzag_encode(parray: &PrimitiveArray) -> VortexResult { let encoded = match parray.ptype() { PType::I8 => zigzag_encode_primitive::(parray.buffer().typed_data(), parray.validity()), PType::I16 => { diff --git a/vortex-zigzag/src/lib.rs b/vortex-zigzag/src/lib.rs index b5a2041248..55da8b3bcd 100644 --- a/vortex-zigzag/src/lib.rs +++ b/vortex-zigzag/src/lib.rs @@ -1,5 +1,5 @@ -use vortex::array::{EncodingRef, ENCODINGS}; use linkme::distributed_slice; +use vortex::array::{EncodingRef, ENCODINGS}; pub use zigzag::*; diff --git a/vortex-zigzag/src/zigzag.rs b/vortex-zigzag/src/zigzag.rs index 3b1ed1737c..d095a39bfb 100644 --- a/vortex-zigzag/src/zigzag.rs +++ b/vortex-zigzag/src/zigzag.rs @@ -9,7 +9,7 @@ use vortex::array::{ }; use vortex::compress::EncodingCompression; use vortex::dtype::{DType, IntWidth, Signedness}; -use vortex::error::{VortexError, EncResult}; +use vortex::error::{VortexError, VortexResult}; use vortex::formatter::{ArrayDisplay, ArrayFormatter}; use vortex::scalar::{NullableScalar, Scalar}; use vortex::serde::{ArraySerde, EncodingSerde}; @@ -29,7 +29,7 @@ impl ZigZagArray { Self::try_new(encoded).unwrap() } - pub fn try_new(encoded: ArrayRef) -> EncResult { + pub fn try_new(encoded: ArrayRef) -> VortexResult { let dtype = match encoded.dtype() { DType::Int(width, Signedness::Unsigned, nullability) => { DType::Int(*width, Signedness::Signed, *nullability) @@ -43,7 +43,7 @@ impl ZigZagArray { }) } - pub fn encode(array: &dyn Array) -> EncResult { + pub fn encode(array: &dyn Array) -> VortexResult { match ArrayKind::from(array) { ArrayKind::Primitive(p) => Ok(zigzag_encode(p)?.boxed()), _ => Err(VortexError::InvalidEncoding(array.encoding().id().clone())), @@ -91,7 +91,7 @@ impl Array for ZigZagArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; let scalar = self.encoded().scalar_at(index)?; @@ -119,7 +119,7 @@ impl Array for ZigZagArray { todo!() } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { Ok(Self::try_new(self.encoded.slice(start, stop)?)?.boxed()) } diff --git a/vortex/src/array/bool/mod.rs b/vortex/src/array/bool/mod.rs index d7db32488b..e41be912e7 100644 --- a/vortex/src/array/bool/mod.rs +++ b/vortex/src/array/bool/mod.rs @@ -9,7 +9,7 @@ use linkme::distributed_slice; use crate::arrow::CombineChunks; use crate::compress::EncodingCompression; use crate::dtype::{DType, Nullability}; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::{NullableScalar, Scalar}; use crate::serde::{ArraySerde, EncodingSerde}; @@ -36,7 +36,7 @@ impl BoolArray { Self::try_new(buffer, validity).unwrap() } - pub fn try_new(buffer: BooleanBuffer, validity: Option) -> EncResult { + pub fn try_new(buffer: BooleanBuffer, validity: Option) -> VortexResult { let validity = validity.filter(|v| !v.is_empty()); check_validity_buffer(validity.as_ref())?; @@ -105,7 +105,7 @@ impl Array for BoolArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; if self.is_valid(index) { @@ -130,7 +130,7 @@ impl Array for BoolArray { )) as ArrowArrayRef)) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; Ok(Self { diff --git a/vortex/src/array/chunked/mod.rs b/vortex/src/array/chunked/mod.rs index 61ac715bcb..eb1fb5f837 100644 --- a/vortex/src/array/chunked/mod.rs +++ b/vortex/src/array/chunked/mod.rs @@ -12,7 +12,7 @@ use crate::array::{ }; use crate::compress::EncodingCompression; use crate::dtype::DType; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::Scalar; use crate::serde::{ArraySerde, EncodingSerde}; @@ -35,7 +35,7 @@ impl ChunkedArray { Self::try_new(chunks, dtype).unwrap() } - pub fn try_new(chunks: Vec, dtype: DType) -> EncResult { + pub fn try_new(chunks: Vec, dtype: DType) -> VortexResult { chunks .iter() .map(|c| c.dtype().as_nullable()) @@ -126,7 +126,7 @@ impl Array for ChunkedArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; let (chunk_index, chunk_offset) = self.find_physical_location(index); self.chunks[chunk_index].scalar_at(chunk_offset) @@ -136,7 +136,7 @@ impl Array for ChunkedArray { Box::new(ChunkedArrowIterator::new(self)) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; let (offset_chunk, offset_in_first_chunk) = self.find_physical_location(start); diff --git a/vortex/src/array/constant/mod.rs b/vortex/src/array/constant/mod.rs index 5695593bcc..42527c948d 100644 --- a/vortex/src/array/constant/mod.rs +++ b/vortex/src/array/constant/mod.rs @@ -11,7 +11,7 @@ use crate::array::{ use crate::arrow::compute::repeat; use crate::compress::EncodingCompression; use crate::dtype::DType; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::Scalar; use crate::serde::{ArraySerde, EncodingSerde}; @@ -80,7 +80,7 @@ impl Array for ConstantArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; Ok(self.scalar.clone()) } @@ -90,7 +90,7 @@ impl Array for ConstantArray { Box::new(std::iter::once(repeat(arrow_scalar.as_ref(), self.length))) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; Ok(ConstantArray::new(self.scalar.clone(), stop - start).boxed()) diff --git a/vortex/src/array/constant/take.rs b/vortex/src/array/constant/take.rs index 9e20e433bb..0760e501fd 100644 --- a/vortex/src/array/constant/take.rs +++ b/vortex/src/array/constant/take.rs @@ -1,10 +1,10 @@ use crate::array::constant::ConstantArray; use crate::array::{Array, ArrayRef}; use crate::compute::take::TakeFn; -use crate::error::EncResult; +use crate::error::VortexResult; impl TakeFn for ConstantArray { - fn take(&self, indices: &dyn Array) -> EncResult { + fn take(&self, indices: &dyn Array) -> VortexResult { Ok(ConstantArray::new(dyn_clone::clone_box(self.scalar()), indices.len()).boxed()) } } diff --git a/vortex/src/array/mod.rs b/vortex/src/array/mod.rs index 82cf446bf1..8be11fd2f1 100644 --- a/vortex/src/array/mod.rs +++ b/vortex/src/array/mod.rs @@ -17,7 +17,7 @@ use crate::array::varbinview::{VarBinViewArray, VARBINVIEW_ENCODING}; use crate::compress::EncodingCompression; use crate::compute::ArrayCompute; use crate::dtype::{DType, Nullability}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::Scalar; use crate::serde::{ArraySerde, EncodingSerde}; @@ -61,11 +61,11 @@ pub trait Array: ArrayDisplay + Debug + Send + Sync + dyn_clone::DynClone + 'sta /// Get statistics for the array fn stats(&self) -> Stats; /// Get scalar value at given index - fn scalar_at(&self, index: usize) -> EncResult>; + fn scalar_at(&self, index: usize) -> VortexResult>; /// Produce arrow batches from the encoding fn iter_arrow(&self) -> Box; /// Limit array to start..stop range - fn slice(&self, start: usize, stop: usize) -> EncResult; + fn slice(&self, start: usize, stop: usize) -> VortexResult; /// Encoding kind of the array fn encoding(&self) -> &'static dyn Encoding; /// Approximate size in bytes of the array. Only takes into account variable size portion of the array @@ -80,7 +80,7 @@ pub trait Array: ArrayDisplay + Debug + Send + Sync + dyn_clone::DynClone + 'sta dyn_clone::clone_trait_object!(Array); -pub fn check_slice_bounds(array: &dyn Array, start: usize, stop: usize) -> EncResult<()> { +pub fn check_slice_bounds(array: &dyn Array, start: usize, stop: usize) -> VortexResult<()> { if start > array.len() { return Err(VortexError::OutOfBounds(start, 0, array.len())); } @@ -90,14 +90,14 @@ pub fn check_slice_bounds(array: &dyn Array, start: usize, stop: usize) -> EncRe Ok(()) } -pub fn check_index_bounds(array: &dyn Array, index: usize) -> EncResult<()> { +pub fn check_index_bounds(array: &dyn Array, index: usize) -> VortexResult<()> { if index >= array.len() { return Err(VortexError::OutOfBounds(index, 0, array.len())); } Ok(()) } -pub fn check_validity_buffer(validity: Option<&ArrayRef>) -> EncResult<()> { +pub fn check_validity_buffer(validity: Option<&ArrayRef>) -> VortexResult<()> { if validity .map(|v| !matches!(v.dtype(), DType::Bool(Nullability::NonNullable))) .unwrap_or(false) diff --git a/vortex/src/array/primitive/mod.rs b/vortex/src/array/primitive/mod.rs index ad5eab531d..910433c33d 100644 --- a/vortex/src/array/primitive/mod.rs +++ b/vortex/src/array/primitive/mod.rs @@ -21,7 +21,7 @@ use crate::array::{ use crate::arrow::CombineChunks; use crate::compress::EncodingCompression; use crate::dtype::DType; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::ptype::{match_each_native_ptype, NativePType, PType}; use crate::scalar::{NullableScalar, Scalar}; @@ -46,7 +46,7 @@ impl PrimitiveArray { Self::try_new(ptype, buffer, validity).unwrap() } - pub fn try_new(ptype: PType, buffer: Buffer, validity: Option) -> EncResult { + pub fn try_new(ptype: PType, buffer: Buffer, validity: Option) -> VortexResult { let validity = validity.filter(|v| !v.is_empty()); check_validity_buffer(validity.as_ref())?; let dtype = if validity.is_some() { @@ -166,7 +166,7 @@ impl Array for PrimitiveArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; if self.is_valid(index) { @@ -202,7 +202,7 @@ impl Array for PrimitiveArray { ))) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; let byte_start = start * self.ptype.byte_width(); diff --git a/vortex/src/array/sparse/mod.rs b/vortex/src/array/sparse/mod.rs index d2456965b4..95d4f5cd0e 100644 --- a/vortex/src/array/sparse/mod.rs +++ b/vortex/src/array/sparse/mod.rs @@ -17,7 +17,7 @@ use crate::arrow::CombineChunks; use crate::compress::EncodingCompression; use crate::compute::search_sorted::{search_sorted_usize, SearchSortedSide}; use crate::dtype::{DType, Nullability, Signedness}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::match_arrow_numeric_type; use crate::scalar::{NullableScalar, Scalar}; @@ -47,7 +47,7 @@ impl SparseArray { Self::try_new(indices, values, len).unwrap() } - pub fn try_new(indices: ArrayRef, values: ArrayRef, len: usize) -> EncResult { + pub fn try_new(indices: ArrayRef, values: ArrayRef, len: usize) -> VortexResult { Self::new_with_offset(indices, values, len, 0) } @@ -56,7 +56,7 @@ impl SparseArray { values: ArrayRef, len: usize, indices_offset: usize, - ) -> EncResult { + ) -> VortexResult { if !matches!( indices.dtype(), DType::Int(_, Signedness::Unsigned, Nullability::NonNullable) @@ -134,7 +134,7 @@ impl Array for SparseArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; // Check whether `true_patch_index` exists in the patch index array @@ -194,7 +194,7 @@ impl Array for SparseArray { )) as Arc)) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; // Find the index of the first patch index that is greater than or equal to the offset of this array diff --git a/vortex/src/array/struct_/mod.rs b/vortex/src/array/struct_/mod.rs index bca2a2e20b..f3562d1f96 100644 --- a/vortex/src/array/struct_/mod.rs +++ b/vortex/src/array/struct_/mod.rs @@ -10,7 +10,7 @@ use linkme::distributed_slice; use crate::arrow::aligned_iter::AlignedArrowArrayIterator; use crate::compress::EncodingCompression; use crate::dtype::{DType, FieldNames}; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::{Scalar, StructScalar}; use crate::serde::{ArraySerde, EncodingSerde}; @@ -112,7 +112,7 @@ impl Array for StructArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { Ok(StructScalar::new( self.dtype.clone(), self.fields @@ -142,7 +142,7 @@ impl Array for StructArray { ) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; let fields = self diff --git a/vortex/src/array/typed/mod.rs b/vortex/src/array/typed/mod.rs index 27c02a3601..b9822a94c9 100644 --- a/vortex/src/array/typed/mod.rs +++ b/vortex/src/array/typed/mod.rs @@ -7,7 +7,7 @@ use linkme::distributed_slice; use crate::array::{Array, ArrayRef, ArrowIterator, Encoding, EncodingId, EncodingRef, ENCODINGS}; use crate::compress::EncodingCompression; use crate::dtype::DType; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::Scalar; use crate::serde::{ArraySerde, EncodingSerde}; @@ -85,7 +85,7 @@ impl Array for TypedArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { let underlying = self.array.scalar_at(index)?; underlying.as_ref().cast(self.dtype()) } @@ -100,7 +100,7 @@ impl Array for TypedArray { ) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { Ok(Self::new(self.array.slice(start, stop)?, self.dtype.clone()).boxed()) } diff --git a/vortex/src/array/varbin/mod.rs b/vortex/src/array/varbin/mod.rs index d52416e958..abd028ec28 100644 --- a/vortex/src/array/varbin/mod.rs +++ b/vortex/src/array/varbin/mod.rs @@ -18,7 +18,7 @@ use crate::array::{ use crate::arrow::CombineChunks; use crate::compress::EncodingCompression; use crate::dtype::{DType, IntWidth, Nullability, Signedness}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::match_each_native_ptype; use crate::ptype::NativePType; @@ -54,7 +54,7 @@ impl VarBinArray { bytes: ArrayRef, dtype: DType, validity: Option, - ) -> EncResult { + ) -> VortexResult { if !matches!(offsets.dtype(), DType::Int(_, _, Nullability::NonNullable)) { return Err(VortexError::UnsupportedOffsetsArrayDType( offsets.dtype().clone(), @@ -64,7 +64,9 @@ impl VarBinArray { bytes.dtype(), DType::Int(IntWidth::_8, Signedness::Unsigned, Nullability::NonNullable) ) { - return Err(VortexError::UnsupportedDataArrayDType(bytes.dtype().clone())); + return Err(VortexError::UnsupportedDataArrayDType( + bytes.dtype().clone(), + )); } if !matches!(dtype, DType::Binary(_) | DType::Utf8(_)) { return Err(VortexError::InvalidDType(dtype)); @@ -176,7 +178,7 @@ impl VarBinArray { } } - pub fn bytes_at(&self, index: usize) -> EncResult> { + pub fn bytes_at(&self, index: usize) -> VortexResult> { check_index_bounds(self, index)?; let (start, end): (usize, usize) = if let Some(p) = self.offsets.maybe_primitive() { @@ -232,7 +234,7 @@ impl Array for VarBinArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { if self.is_valid(index) { self.bytes_at(index).map(|bytes| { if matches!(self.dtype, DType::Utf8(_)) { @@ -269,7 +271,7 @@ impl Array for VarBinArray { Box::new(iter::once(make_array(data))) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; Ok(VarBinArray::new( diff --git a/vortex/src/array/varbin/stats.rs b/vortex/src/array/varbin/stats.rs index 3c7fab78ee..12f3743a29 100644 --- a/vortex/src/array/varbin/stats.rs +++ b/vortex/src/array/varbin/stats.rs @@ -5,11 +5,11 @@ use crate::array::varbin::VarBinArray; use crate::array::varbinview::VarBinViewArray; use crate::array::Array; use crate::dtype::DType; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::stats::{Stat, StatsCompute, StatsSet}; pub trait BinaryArray { - fn bytes_at(&self, index: usize) -> EncResult>; + fn bytes_at(&self, index: usize) -> VortexResult>; } impl StatsCompute for T @@ -66,13 +66,13 @@ where } impl BinaryArray for VarBinArray { - fn bytes_at(&self, index: usize) -> EncResult> { + fn bytes_at(&self, index: usize) -> VortexResult> { VarBinArray::bytes_at(self, index) } } impl BinaryArray for VarBinViewArray { - fn bytes_at(&self, index: usize) -> EncResult> { + fn bytes_at(&self, index: usize) -> VortexResult> { VarBinViewArray::bytes_at(self, index) } } diff --git a/vortex/src/array/varbinview/mod.rs b/vortex/src/array/varbinview/mod.rs index b62080feee..544e6497b5 100644 --- a/vortex/src/array/varbinview/mod.rs +++ b/vortex/src/array/varbinview/mod.rs @@ -18,7 +18,7 @@ use crate::array::{ use crate::arrow::CombineChunks; use crate::compress::EncodingCompression; use crate::dtype::{DType, IntWidth, Nullability, Signedness}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::formatter::{ArrayDisplay, ArrayFormatter}; use crate::scalar::{NullableScalar, Scalar}; use crate::serde::{ArraySerde, EncodingSerde}; @@ -103,7 +103,7 @@ impl VarBinViewArray { data: Vec, dtype: DType, validity: Option, - ) -> EncResult { + ) -> VortexResult { if !matches!( views.dtype(), DType::Int(IntWidth::_8, Signedness::Unsigned, Nullability::NonNullable) @@ -184,7 +184,7 @@ impl VarBinViewArray { self.validity.as_ref() } - pub fn bytes_at(&self, index: usize) -> EncResult> { + pub fn bytes_at(&self, index: usize) -> VortexResult> { let view = self.view_at(index); unsafe { if view.inlined.size > 12 { @@ -246,7 +246,7 @@ impl Array for VarBinViewArray { Stats::new(&self.stats, self) } - fn scalar_at(&self, index: usize) -> EncResult> { + fn scalar_at(&self, index: usize) -> VortexResult> { if self.is_valid(index) { self.bytes_at(index).map(|bytes| { if matches!(self.dtype, DType::Utf8(_)) { @@ -289,7 +289,7 @@ impl Array for VarBinViewArray { Box::new(iter::once(data_arr)) } - fn slice(&self, start: usize, stop: usize) -> EncResult { + fn slice(&self, start: usize, stop: usize) -> VortexResult { check_slice_bounds(self, start, stop)?; Ok(Self { diff --git a/vortex/src/arrow/convert.rs b/vortex/src/arrow/convert.rs index 71c763345a..a0a032a4f2 100644 --- a/vortex/src/arrow/convert.rs +++ b/vortex/src/arrow/convert.rs @@ -9,7 +9,7 @@ use crate::array::typed::TypedArray; use crate::array::{Array, ArrayRef}; use crate::dtype::DType::*; use crate::dtype::{DType, FloatWidth, IntWidth, Nullability, TimeUnit}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::ptype::PType; impl From for ArrayRef { @@ -41,7 +41,7 @@ impl From for ArrayRef { impl TryFrom for DType { type Error = VortexError; - fn try_from(value: SchemaRef) -> EncResult { + fn try_from(value: SchemaRef) -> VortexResult { Ok(Struct( value .fields() @@ -52,7 +52,7 @@ impl TryFrom for DType { .fields() .iter() .map(|f| f.data_type().try_into_dtype(f.is_nullable())) - .collect::>>()?, + .collect::>>()?, )) } } @@ -60,7 +60,7 @@ impl TryFrom for DType { impl TryFrom<&DataType> for PType { type Error = VortexError; - fn try_from(value: &DataType) -> EncResult { + fn try_from(value: &DataType) -> VortexResult { match value { DataType::Int8 => Ok(PType::I8), DataType::Int16 => Ok(PType::I16), @@ -85,11 +85,11 @@ impl TryFrom<&DataType> for PType { } pub trait TryIntoDType { - fn try_into_dtype(self, is_nullable: bool) -> EncResult; + fn try_into_dtype(self, is_nullable: bool) -> VortexResult; } impl TryIntoDType for &DataType { - fn try_into_dtype(self, is_nullable: bool) -> EncResult { + fn try_into_dtype(self, is_nullable: bool) -> VortexResult { use crate::dtype::Nullability::*; use crate::dtype::Signedness::*; @@ -124,7 +124,7 @@ impl TryIntoDType for &DataType { f.iter().map(|f| Arc::new(f.name().clone())).collect(), f.iter() .map(|f| f.data_type().try_into_dtype(f.is_nullable())) - .collect::>>()?, + .collect::>>()?, )), DataType::Dictionary(_, v) => v.as_ref().try_into_dtype(is_nullable), DataType::Decimal128(p, s) | DataType::Decimal256(p, s) => { @@ -149,7 +149,7 @@ impl TryIntoDType for &DataType { impl TryFrom<&FieldRef> for DType { type Error = VortexError; - fn try_from(value: &FieldRef) -> EncResult { + fn try_from(value: &FieldRef) -> VortexResult { value.data_type().try_into_dtype(value.is_nullable()) } } diff --git a/vortex/src/compute/add.rs b/vortex/src/compute/add.rs index f4ec82931e..6ef1002204 100644 --- a/vortex/src/compute/add.rs +++ b/vortex/src/compute/add.rs @@ -1,10 +1,10 @@ use crate::array::constant::ConstantArray; use crate::array::{Array, ArrayKind, ArrayRef}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::Scalar; // TODO(ngates): convert this to arithmetic operations with macro over the kernel. -pub fn add(lhs: &dyn Array, rhs: &dyn Array) -> EncResult { +pub fn add(lhs: &dyn Array, rhs: &dyn Array) -> VortexResult { // Check that the arrays are the same length. let length = lhs.len(); if rhs.len() != length { @@ -21,7 +21,7 @@ pub fn add(lhs: &dyn Array, rhs: &dyn Array) -> EncResult { } } -pub fn add_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> EncResult { +pub fn add_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> VortexResult { match ArrayKind::from(lhs) { ArrayKind::Constant(lhs) => { Ok(ConstantArray::new(add_scalars(lhs.scalar(), rhs)?, lhs.len()).boxed()) @@ -30,7 +30,7 @@ pub fn add_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> EncResult { } } -pub fn add_scalars(_lhs: &dyn Scalar, _rhs: &dyn Scalar) -> EncResult> { +pub fn add_scalars(_lhs: &dyn Scalar, _rhs: &dyn Scalar) -> VortexResult> { // Might need to improve this implementation... Ok(24.into()) } diff --git a/vortex/src/compute/as_contiguous.rs b/vortex/src/compute/as_contiguous.rs index b8e4c4dbf7..e1e1295e8c 100644 --- a/vortex/src/compute/as_contiguous.rs +++ b/vortex/src/compute/as_contiguous.rs @@ -5,11 +5,11 @@ use crate::array::bool::{BoolArray, BOOL_ENCODING}; use crate::array::downcast::DowncastArrayBuiltin; use crate::array::primitive::{PrimitiveArray, PRIMITIVE_ENCODING}; use crate::array::{Array, ArrayRef}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::ptype::{match_each_native_ptype, NativePType}; use vortex_alloc::{AlignedVec, ALIGNED_ALLOCATOR}; -pub fn as_contiguous(arrays: Vec) -> EncResult { +pub fn as_contiguous(arrays: Vec) -> VortexResult { if arrays.is_empty() { return Err(VortexError::ComputeError("No arrays to concatenate".into())); } @@ -32,7 +32,7 @@ pub fn as_contiguous(arrays: Vec) -> EncResult { } } -fn bool_as_contiguous(arrays: Vec<&BoolArray>) -> EncResult { +fn bool_as_contiguous(arrays: Vec<&BoolArray>) -> VortexResult { // TODO(ngates): implement a HasValidity trait to avoid this duplicate code. let validity = if arrays.iter().all(|a| a.validity().is_none()) { None @@ -60,7 +60,7 @@ fn bool_as_contiguous(arrays: Vec<&BoolArray>) -> EncResult { )) } -fn primitive_as_contiguous(arrays: Vec<&PrimitiveArray>) -> EncResult { +fn primitive_as_contiguous(arrays: Vec<&PrimitiveArray>) -> VortexResult { if !arrays.iter().map(|chunk| (*chunk).ptype()).all_equal() { return Err(VortexError::ComputeError( "Chunks have differing ptypes".into(), diff --git a/vortex/src/compute/search_sorted.rs b/vortex/src/compute/search_sorted.rs index 4d902ddf3d..42677dd9e7 100644 --- a/vortex/src/compute/search_sorted.rs +++ b/vortex/src/compute/search_sorted.rs @@ -1,5 +1,5 @@ use crate::array::Array; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::polars::IntoPolarsSeries; use crate::polars::IntoPolarsValue; use crate::scalar::Scalar; @@ -24,7 +24,7 @@ pub fn search_sorted_usize( indices: &dyn Array, index: usize, side: SearchSortedSide, -) -> EncResult { +) -> VortexResult { let enc_scalar: Box = index.into(); // Convert index into correctly typed Arrow scalar. let enc_scalar = enc_scalar.cast(indices.dtype())?; diff --git a/vortex/src/compute/take.rs b/vortex/src/compute/take.rs index fcdbbb086f..cbcaa458f1 100644 --- a/vortex/src/compute/take.rs +++ b/vortex/src/compute/take.rs @@ -1,11 +1,11 @@ use crate::array::{Array, ArrayRef}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; pub trait TakeFn { - fn take(&self, indices: &dyn Array) -> EncResult; + fn take(&self, indices: &dyn Array) -> VortexResult; } -pub fn take(array: &dyn Array, indices: &dyn Array) -> EncResult { +pub fn take(array: &dyn Array, indices: &dyn Array) -> VortexResult { array .compute() .and_then(|c| c.take()) diff --git a/vortex/src/error.rs b/vortex/src/error.rs index 6d460bd680..9fa652a6f9 100644 --- a/vortex/src/error.rs +++ b/vortex/src/error.rs @@ -77,7 +77,7 @@ pub enum VortexError { IndexArrayMustBeStrictSorted, } -pub type EncResult = Result; +pub type VortexResult = Result; // Wrap up external errors so that we can implement a dumb PartialEq #[derive(Debug)] diff --git a/vortex/src/ptype.rs b/vortex/src/ptype.rs index 6baf327dc8..4755955b20 100644 --- a/vortex/src/ptype.rs +++ b/vortex/src/ptype.rs @@ -5,7 +5,7 @@ use arrow::datatypes::ArrowNativeType; use half::f16; use crate::dtype::{DType, FloatWidth, IntWidth, Signedness}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::Scalar; #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash)] @@ -33,7 +33,7 @@ pub trait NativePType: + Default + ArrowNativeType + RefUnwindSafe - + TryFrom, Error =VortexError> + + TryFrom, Error = VortexError> { const PTYPE: PType; } @@ -126,7 +126,7 @@ impl PType { impl TryFrom<&DType> for PType { type Error = VortexError; - fn try_from(value: &DType) -> EncResult { + fn try_from(value: &DType) -> VortexResult { use Signedness::*; match value { DType::Int(w, s, _) => match w { diff --git a/vortex/src/scalar/binary.rs b/vortex/src/scalar/binary.rs index 21b18d55a3..ecaded22fc 100644 --- a/vortex/src/scalar/binary.rs +++ b/vortex/src/scalar/binary.rs @@ -1,5 +1,5 @@ use crate::dtype::{DType, Nullability}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::Scalar; use std::any::Any; use std::fmt::{Display, Formatter}; @@ -50,7 +50,7 @@ impl Scalar for BinaryScalar { &DType::Binary(Nullability::NonNullable) } - fn cast(&self, _dtype: &DType) -> EncResult> { + fn cast(&self, _dtype: &DType) -> VortexResult> { todo!() } diff --git a/vortex/src/scalar/bool.rs b/vortex/src/scalar/bool.rs index b343cfeac5..5a5d1be662 100644 --- a/vortex/src/scalar/bool.rs +++ b/vortex/src/scalar/bool.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::fmt::{Display, Formatter}; use crate::dtype::{DType, Nullability}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::{NullableScalar, Scalar}; #[derive(Debug, Clone, PartialEq, PartialOrd)] @@ -51,7 +51,7 @@ impl Scalar for BoolScalar { &DType::Bool(Nullability::NonNullable) } - fn cast(&self, dtype: &DType) -> EncResult> { + fn cast(&self, dtype: &DType) -> VortexResult> { match dtype { DType::Bool(Nullability::NonNullable) => Ok(self.clone().boxed()), DType::Bool(Nullability::Nullable) => { @@ -77,7 +77,7 @@ impl TryFrom> for bool { type Error = VortexError; #[inline] - fn try_from(value: Box) -> EncResult { + fn try_from(value: Box) -> VortexResult { value.as_ref().try_into() } } @@ -85,7 +85,7 @@ impl TryFrom> for bool { impl TryFrom<&dyn Scalar> for bool { type Error = VortexError; - fn try_from(value: &dyn Scalar) -> EncResult { + fn try_from(value: &dyn Scalar) -> VortexResult { if let Some(bool_scalar) = value .as_nonnull() .and_then(|v| v.as_any().downcast_ref::()) diff --git a/vortex/src/scalar/list.rs b/vortex/src/scalar/list.rs index c960ccc11e..8636ae6926 100644 --- a/vortex/src/scalar/list.rs +++ b/vortex/src/scalar/list.rs @@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter}; use itertools::Itertools; use crate::dtype::{DType, Nullability}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::{NullableScalar, Scalar}; #[derive(Debug, Clone, PartialEq)] @@ -54,7 +54,7 @@ impl Scalar for ListScalar { &self.dtype } - fn cast(&self, dtype: &DType) -> EncResult> { + fn cast(&self, dtype: &DType) -> VortexResult> { match dtype { DType::List(field_dtype, n) => { let new_fields: Vec> = self @@ -96,7 +96,7 @@ impl>> From> for Box { } } -impl, Error =VortexError>> TryFrom<&dyn Scalar> for ListScalarVec { +impl, Error = VortexError>> TryFrom<&dyn Scalar> for ListScalarVec { type Error = VortexError; fn try_from(value: &dyn Scalar) -> Result { @@ -115,7 +115,9 @@ impl, Error =VortexError>> TryFrom<&dyn Scalar> for L } } -impl, Error =VortexError>> TryFrom> for ListScalarVec { +impl, Error = VortexError>> TryFrom> + for ListScalarVec +{ type Error = VortexError; fn try_from(value: Box) -> Result { diff --git a/vortex/src/scalar/localtime.rs b/vortex/src/scalar/localtime.rs index c7874d91b8..9a4ef52cf1 100644 --- a/vortex/src/scalar/localtime.rs +++ b/vortex/src/scalar/localtime.rs @@ -1,5 +1,5 @@ use crate::dtype::{DType, Nullability, TimeUnit}; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::scalar::{PScalar, Scalar}; use std::any::Any; use std::cmp::Ordering; @@ -62,7 +62,7 @@ impl Scalar for LocalTimeScalar { &self.dtype } - fn cast(&self, _dtype: &DType) -> EncResult> { + fn cast(&self, _dtype: &DType) -> VortexResult> { todo!() } diff --git a/vortex/src/scalar/mod.rs b/vortex/src/scalar/mod.rs index 75e3bd30a4..0f7e287aa5 100644 --- a/vortex/src/scalar/mod.rs +++ b/vortex/src/scalar/mod.rs @@ -13,7 +13,7 @@ pub use struct_::*; pub use utf8::*; use crate::dtype::DType; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::ptype::NativePType; mod arrow; @@ -44,7 +44,7 @@ pub trait Scalar: Display + Debug + dyn_clone::DynClone + Send + Sync + 'static /// the logical type. fn dtype(&self) -> &DType; - fn cast(&self, dtype: &DType) -> EncResult>; + fn cast(&self, dtype: &DType) -> VortexResult>; fn nbytes(&self) -> usize; } diff --git a/vortex/src/scalar/null.rs b/vortex/src/scalar/null.rs index cde103f400..8d0ea4418d 100644 --- a/vortex/src/scalar/null.rs +++ b/vortex/src/scalar/null.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::fmt::{Display, Formatter}; use crate::dtype::DType; -use crate::error::EncResult; +use crate::error::VortexResult; use crate::scalar::{NullableScalar, Scalar}; #[derive(Debug, Clone, PartialEq)] @@ -52,7 +52,7 @@ impl Scalar for NullScalar { &DType::Null } - fn cast(&self, dtype: &DType) -> EncResult> { + fn cast(&self, dtype: &DType) -> VortexResult> { Ok(NullableScalar::none(dtype.clone()).boxed()) } diff --git a/vortex/src/scalar/nullable.rs b/vortex/src/scalar/nullable.rs index 0941eaab84..61ffb6a5d8 100644 --- a/vortex/src/scalar/nullable.rs +++ b/vortex/src/scalar/nullable.rs @@ -3,7 +3,7 @@ use std::fmt::{Display, Formatter}; use std::mem::size_of; use crate::dtype::DType; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::{NullScalar, Scalar}; #[derive(Debug, Clone, PartialEq, PartialOrd)] @@ -63,7 +63,7 @@ impl Scalar for NullableScalar { } } - fn cast(&self, _dtype: &DType) -> EncResult> { + fn cast(&self, _dtype: &DType) -> VortexResult> { todo!() } @@ -99,7 +99,7 @@ impl>> From> for Box } } -impl, Error =VortexError>> TryFrom<&dyn Scalar> +impl, Error = VortexError>> TryFrom<&dyn Scalar> for NullableScalarOption { type Error = VortexError; @@ -116,7 +116,7 @@ impl, Error =VortexError>> TryFrom<&dyn Scalar> } } -impl, Error =VortexError>> TryFrom> +impl, Error = VortexError>> TryFrom> for NullableScalarOption { type Error = VortexError; diff --git a/vortex/src/scalar/primitive.rs b/vortex/src/scalar/primitive.rs index 7e3180c809..088f4de22c 100644 --- a/vortex/src/scalar/primitive.rs +++ b/vortex/src/scalar/primitive.rs @@ -5,7 +5,7 @@ use std::mem::size_of; use half::f16; use crate::dtype::{DType, Nullability}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::ptype::PType; use crate::scalar::{LocalTimeScalar, Scalar}; @@ -43,7 +43,7 @@ impl PScalar { // General conversion function that handles casting primitive scalar to non primitive. // If target dtype can be converted to ptype you should use cast_ptype. - pub fn cast_dtype(&self, dtype: DType) -> EncResult> { + pub fn cast_dtype(&self, dtype: DType) -> VortexResult> { macro_rules! from_int { ($dtype:ident , $ps:ident) => { match $dtype { @@ -64,7 +64,7 @@ impl PScalar { } } - pub fn cast_ptype(&self, ptype: PType) -> EncResult> { + pub fn cast_ptype(&self, ptype: PType) -> VortexResult> { macro_rules! from_int { ($ptype:ident , $v:ident) => { match $ptype { @@ -151,8 +151,8 @@ impl Scalar for PScalar { self.ptype().into() } - fn cast(&self, dtype: &DType) -> EncResult> { - let ptype: EncResult = dtype.try_into(); + fn cast(&self, dtype: &DType) -> VortexResult> { + let ptype: VortexResult = dtype.try_into(); ptype .and_then(|p| self.cast_ptype(p)) .or_else(|_| self.cast_dtype(dtype.clone())) @@ -176,7 +176,7 @@ macro_rules! pscalar { type Error = VortexError; #[inline] - fn try_from(value: Box) -> EncResult { + fn try_from(value: Box) -> VortexResult { value.as_ref().try_into() } } @@ -184,7 +184,7 @@ macro_rules! pscalar { impl TryFrom<&dyn Scalar> for $T { type Error = VortexError; - fn try_from(value: &dyn Scalar) -> EncResult { + fn try_from(value: &dyn Scalar) -> VortexResult { if let Some(pscalar) = value .as_nonnull() .and_then(|v| v.as_any().downcast_ref::()) @@ -223,7 +223,7 @@ impl From for Box { impl TryFrom> for usize { type Error = VortexError; - fn try_from(value: Box) -> EncResult { + fn try_from(value: Box) -> VortexResult { value.as_ref().try_into() } } @@ -231,7 +231,7 @@ impl TryFrom> for usize { impl TryFrom<&dyn Scalar> for usize { type Error = VortexError; - fn try_from(value: &dyn Scalar) -> EncResult { + fn try_from(value: &dyn Scalar) -> VortexResult { macro_rules! match_each_pscalar_integer { ($self:expr, | $_:tt $pscalar:ident | $($body:tt)*) => ({ macro_rules! __with_pscalar__ {( $_ $pscalar:ident ) => ( $($body)* )} @@ -300,7 +300,9 @@ mod test { let scalar: Box = (-10i16).into(); assert_eq!( scalar.as_ref().try_into(), - Err::(VortexError::ComputeError("required positive integer".into())) + Err::(VortexError::ComputeError( + "required positive integer".into() + )) ); } diff --git a/vortex/src/scalar/struct_.rs b/vortex/src/scalar/struct_.rs index adfadf5b26..f0761e3303 100644 --- a/vortex/src/scalar/struct_.rs +++ b/vortex/src/scalar/struct_.rs @@ -5,7 +5,7 @@ use std::fmt::{Display, Formatter}; use itertools::Itertools; use crate::dtype::DType; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::Scalar; #[derive(Debug, Clone, PartialEq)] @@ -57,7 +57,7 @@ impl Scalar for StructScalar { &self.dtype } - fn cast(&self, dtype: &DType) -> EncResult> { + fn cast(&self, dtype: &DType) -> VortexResult> { match dtype { DType::Struct(names, field_dtypes) => { if field_dtypes.len() != self.values.len() { diff --git a/vortex/src/scalar/utf8.rs b/vortex/src/scalar/utf8.rs index 2b1d9e4003..975b5ebdaf 100644 --- a/vortex/src/scalar/utf8.rs +++ b/vortex/src/scalar/utf8.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::fmt::{Display, Formatter}; use crate::dtype::{DType, Nullability}; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::scalar::Scalar; #[derive(Debug, Clone, PartialEq, PartialOrd)] @@ -50,7 +50,7 @@ impl Scalar for Utf8Scalar { &DType::Utf8(Nullability::NonNullable) } - fn cast(&self, _dtype: &DType) -> EncResult> { + fn cast(&self, _dtype: &DType) -> VortexResult> { todo!() } diff --git a/vortex/src/stats.rs b/vortex/src/stats.rs index e6273227de..e559f2d41c 100644 --- a/vortex/src/stats.rs +++ b/vortex/src/stats.rs @@ -5,7 +5,7 @@ use std::sync::RwLock; use itertools::Itertools; -use crate::error::{VortexError, EncResult}; +use crate::error::{VortexError, VortexResult}; use crate::ptype::NativePType; use crate::scalar::{ListScalarVec, Scalar}; @@ -38,10 +38,10 @@ impl StatsSet { StatsSet(HashMap::from([(stat, value)])) } - fn get_as, Error =VortexError>>( + fn get_as, Error = VortexError>>( &self, stat: &Stat, - ) -> EncResult> { + ) -> VortexResult> { self.0.get(stat).map(|v| T::try_from(v.clone())).transpose() } @@ -241,7 +241,10 @@ impl<'a> Stats<'a> { self.cache.read().unwrap().0.get(stat).cloned() } - pub fn get_as, Error =VortexError>>(&self, stat: &Stat) -> Option { + pub fn get_as, Error = VortexError>>( + &self, + stat: &Stat, + ) -> Option { self.get(stat).map(|v| T::try_from(v).unwrap()) } @@ -263,14 +266,14 @@ impl<'a> Stats<'a> { .map(|v| T::try_from(v.cast(T::PTYPE.into()).unwrap()).unwrap()) } - pub fn get_or_compute_as, Error =VortexError>>( + pub fn get_or_compute_as, Error = VortexError>>( &self, stat: &Stat, ) -> Option { self.get_or_compute(stat).map(|v| T::try_from(v).unwrap()) } - pub fn get_or_compute_or, Error =VortexError>>( + pub fn get_or_compute_or, Error = VortexError>>( &self, default: T, stat: &Stat,