Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename
Browse files Browse the repository at this point in the history
robert3005 committed Feb 27, 2024
1 parent f79bd78 commit 9464dbb
Showing 52 changed files with 187 additions and 176 deletions.
4 changes: 2 additions & 2 deletions bench-vortex/benches/compress_benchmark.rs
Original file line number Diff line number Diff line change
@@ -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::<EncResult<Vec<ArrayRef>>>()
.collect::<VortexResult<Vec<ArrayRef>>>()
.unwrap();
let chunked = ChunkedArray::new(chunks, dtype);
println!(
4 changes: 2 additions & 2 deletions bench-vortex/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::<EncResult<Vec<ArrayRef>>>()
.collect::<VortexResult<Vec<ArrayRef>>>()
.unwrap();
let chunked = ChunkedArray::new(chunks, dtype);
println!(
6 changes: 4 additions & 2 deletions pyvortex/src/array.rs
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion pyvortex/src/dtype.rs
Original file line number Diff line number Diff line change
@@ -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;

2 changes: 1 addition & 1 deletion pyvortex/src/encode.rs
Original file line number Diff line number Diff line change
@@ -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.
///
2 changes: 1 addition & 1 deletion pyvortex/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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]
10 changes: 5 additions & 5 deletions vortex-alp/src/alp.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>,
) -> EncResult<Self> {
) -> VortexResult<Self> {
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<ArrayRef> {
pub fn encode(array: &dyn Array) -> VortexResult<ArrayRef> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
Ok(Self::try_new(
self.encoded().slice(start, stop)?,
self.exponents(),
2 changes: 1 addition & 1 deletion vortex-alp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions vortex-dict/src/dict.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
pub fn try_new(codes: ArrayRef, dict: ArrayRef) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;
Ok(Self::new(self.codes().slice(start, stop)?, self.dict.clone()).boxed())
}
2 changes: 1 addition & 1 deletion vortex-dict/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vortex::array::{EncodingRef, ENCODINGS};
use linkme::distributed_slice;
use vortex::array::{EncodingRef, ENCODINGS};

pub use compress::*;
pub use dict::*;
10 changes: 5 additions & 5 deletions vortex-ffor/src/ffor.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Scalar>,
num_bits: u8,
len: usize,
) -> EncResult<Self> {
) -> VortexResult<Self> {
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<ArrayRef> {
pub fn encode(array: &dyn Array) -> VortexResult<ArrayRef> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, _start: usize, _stop: usize) -> VortexResult<ArrayRef> {
unimplemented!("FFoRArray::slice")
}

2 changes: 1 addition & 1 deletion vortex-ffor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion vortex-ree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vortex::array::{EncodingRef, ENCODINGS};
use linkme::distributed_slice;
use vortex::array::{EncodingRef, ENCODINGS};

pub use ree::*;

14 changes: 7 additions & 7 deletions vortex-ree/src/ree.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>,
length: usize,
) -> EncResult<Self> {
) -> VortexResult<Self> {
check_validity_buffer(validity.as_ref())?;

if !matches!(
@@ -82,15 +82,15 @@ impl REEArray {
})
}

pub fn find_physical_index(&self, index: usize) -> EncResult<usize> {
pub fn find_physical_index(&self, index: usize) -> VortexResult<usize> {
compute::search_sorted::search_sorted_usize(
self.ends(),
index + self.offset,
SearchSortedSide::Right,
)
}

pub fn encode(array: &dyn Array) -> EncResult<ArrayRef> {
pub fn encode(array: &dyn Array) -> VortexResult<ArrayRef> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
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<T: AsRef<dyn Array>>(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};
14 changes: 7 additions & 7 deletions vortex-roaring/src/boolean/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
pub fn encode(array: &dyn Array) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
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)?;

8 changes: 4 additions & 4 deletions vortex-roaring/src/boolean/stats.rs
Original file line number Diff line number Diff line change
@@ -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)?;

14 changes: 7 additions & 7 deletions vortex-roaring/src/integer/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
pub fn try_new(bitmap: Bitmap, ptype: PType) -> VortexResult<Self> {
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<Self> {
pub fn encode(array: &dyn Array) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
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::<u32>(vec![2, 12, 22, 32]);
let array = RoaringIntArray::encode(ints)?;

2 changes: 1 addition & 1 deletion vortex-roaring/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion vortex-roaring/src/serde_tests.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef> {
let mut buf = Vec::<u8>::new();
4 changes: 2 additions & 2 deletions vortex-zigzag/src/compress.rs
Original file line number Diff line number Diff line change
@@ -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<ZigZagArray> {
pub fn zigzag_encode(parray: &PrimitiveArray) -> VortexResult<ZigZagArray> {
let encoded = match parray.ptype() {
PType::I8 => zigzag_encode_primitive::<i8>(parray.buffer().typed_data(), parray.validity()),
PType::I16 => {
2 changes: 1 addition & 1 deletion vortex-zigzag/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vortex::array::{EncodingRef, ENCODINGS};
use linkme::distributed_slice;
use vortex::array::{EncodingRef, ENCODINGS};

pub use zigzag::*;

10 changes: 5 additions & 5 deletions vortex-zigzag/src/zigzag.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
pub fn try_new(encoded: ArrayRef) -> VortexResult<Self> {
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<ArrayRef> {
pub fn encode(array: &dyn Array) -> VortexResult<ArrayRef> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
Ok(Self::try_new(self.encoded.slice(start, stop)?)?.boxed())
}

8 changes: 4 additions & 4 deletions vortex/src/array/bool/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>) -> EncResult<Self> {
pub fn try_new(buffer: BooleanBuffer, validity: Option<ArrayRef>) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

Ok(Self {
8 changes: 4 additions & 4 deletions vortex/src/array/chunked/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>, dtype: DType) -> EncResult<Self> {
pub fn try_new(chunks: Vec<ArrayRef>, dtype: DType) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

let (offset_chunk, offset_in_first_chunk) = self.find_physical_location(start);
6 changes: 3 additions & 3 deletions vortex/src/array/constant/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

Ok(ConstantArray::new(self.scalar.clone(), stop - start).boxed())
4 changes: 2 additions & 2 deletions vortex/src/array/constant/take.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef> {
fn take(&self, indices: &dyn Array) -> VortexResult<ArrayRef> {
Ok(ConstantArray::new(dyn_clone::clone_box(self.scalar()), indices.len()).boxed())
}
}
12 changes: 6 additions & 6 deletions vortex/src/array/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>>;
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>>;
/// Produce arrow batches from the encoding
fn iter_arrow(&self) -> Box<ArrowIterator>;
/// Limit array to start..stop range
fn slice(&self, start: usize, stop: usize) -> EncResult<ArrayRef>;
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef>;
/// 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)
8 changes: 4 additions & 4 deletions vortex/src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>) -> EncResult<Self> {
pub fn try_new(ptype: PType, buffer: Buffer, validity: Option<ArrayRef>) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

let byte_start = start * self.ptype.byte_width();
10 changes: 5 additions & 5 deletions vortex/src/array/sparse/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
pub fn try_new(indices: ArrayRef, values: ArrayRef, len: usize) -> VortexResult<Self> {
Self::new_with_offset(indices, values, len, 0)
}

@@ -56,7 +56,7 @@ impl SparseArray {
values: ArrayRef,
len: usize,
indices_offset: usize,
) -> EncResult<Self> {
) -> VortexResult<Self> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<dyn ArrowArray>))
}

fn slice(&self, start: usize, stop: usize) -> EncResult<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
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
6 changes: 3 additions & 3 deletions vortex/src/array/struct_/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
Ok(StructScalar::new(
self.dtype.clone(),
self.fields
@@ -142,7 +142,7 @@ impl Array for StructArray {
)
}

fn slice(&self, start: usize, stop: usize) -> EncResult<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

let fields = self
6 changes: 3 additions & 3 deletions vortex/src/array/typed/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
Ok(Self::new(self.array.slice(start, stop)?, self.dtype.clone()).boxed())
}

14 changes: 8 additions & 6 deletions vortex/src/array/varbin/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>,
) -> EncResult<Self> {
) -> VortexResult<Self> {
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<Vec<u8>> {
pub fn bytes_at(&self, index: usize) -> VortexResult<Vec<u8>> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

Ok(VarBinArray::new(
8 changes: 4 additions & 4 deletions vortex/src/array/varbin/stats.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<u8>>;
fn bytes_at(&self, index: usize) -> VortexResult<Vec<u8>>;
}

impl<T> StatsCompute for T
@@ -66,13 +66,13 @@ where
}

impl BinaryArray for VarBinArray {
fn bytes_at(&self, index: usize) -> EncResult<Vec<u8>> {
fn bytes_at(&self, index: usize) -> VortexResult<Vec<u8>> {
VarBinArray::bytes_at(self, index)
}
}

impl BinaryArray for VarBinViewArray {
fn bytes_at(&self, index: usize) -> EncResult<Vec<u8>> {
fn bytes_at(&self, index: usize) -> VortexResult<Vec<u8>> {
VarBinViewArray::bytes_at(self, index)
}
}
10 changes: 5 additions & 5 deletions vortex/src/array/varbinview/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>,
dtype: DType,
validity: Option<ArrayRef>,
) -> EncResult<Self> {
) -> VortexResult<Self> {
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<Vec<u8>> {
pub fn bytes_at(&self, index: usize) -> VortexResult<Vec<u8>> {
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<Box<dyn Scalar>> {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
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<ArrayRef> {
fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
check_slice_bounds(self, start, stop)?;

Ok(Self {
16 changes: 8 additions & 8 deletions vortex/src/arrow/convert.rs
Original file line number Diff line number Diff line change
@@ -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<RecordBatch> for ArrayRef {
@@ -41,7 +41,7 @@ impl From<RecordBatch> for ArrayRef {
impl TryFrom<SchemaRef> for DType {
type Error = VortexError;

fn try_from(value: SchemaRef) -> EncResult<Self> {
fn try_from(value: SchemaRef) -> VortexResult<Self> {
Ok(Struct(
value
.fields()
@@ -52,15 +52,15 @@ impl TryFrom<SchemaRef> for DType {
.fields()
.iter()
.map(|f| f.data_type().try_into_dtype(f.is_nullable()))
.collect::<EncResult<Vec<DType>>>()?,
.collect::<VortexResult<Vec<DType>>>()?,
))
}
}

impl TryFrom<&DataType> for PType {
type Error = VortexError;

fn try_from(value: &DataType) -> EncResult<Self> {
fn try_from(value: &DataType) -> VortexResult<Self> {
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<DType>;
fn try_into_dtype(self, is_nullable: bool) -> VortexResult<DType>;
}

impl TryIntoDType for &DataType {
fn try_into_dtype(self, is_nullable: bool) -> EncResult<DType> {
fn try_into_dtype(self, is_nullable: bool) -> VortexResult<DType> {
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::<EncResult<Vec<DType>>>()?,
.collect::<VortexResult<Vec<DType>>>()?,
)),
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<Self> {
fn try_from(value: &FieldRef) -> VortexResult<Self> {
value.data_type().try_into_dtype(value.is_nullable())
}
}
8 changes: 4 additions & 4 deletions vortex/src/compute/add.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef> {
pub fn add(lhs: &dyn Array, rhs: &dyn Array) -> VortexResult<ArrayRef> {
// 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<ArrayRef> {
}
}

pub fn add_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> EncResult<ArrayRef> {
pub fn add_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> VortexResult<ArrayRef> {
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<ArrayRef> {
}
}

pub fn add_scalars(_lhs: &dyn Scalar, _rhs: &dyn Scalar) -> EncResult<Box<dyn Scalar>> {
pub fn add_scalars(_lhs: &dyn Scalar, _rhs: &dyn Scalar) -> VortexResult<Box<dyn Scalar>> {
// Might need to improve this implementation...
Ok(24.into())
}
8 changes: 4 additions & 4 deletions vortex/src/compute/as_contiguous.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>) -> EncResult<ArrayRef> {
pub fn as_contiguous(arrays: Vec<ArrayRef>) -> VortexResult<ArrayRef> {
if arrays.is_empty() {
return Err(VortexError::ComputeError("No arrays to concatenate".into()));
}
@@ -32,7 +32,7 @@ pub fn as_contiguous(arrays: Vec<ArrayRef>) -> EncResult<ArrayRef> {
}
}

fn bool_as_contiguous(arrays: Vec<&BoolArray>) -> EncResult<BoolArray> {
fn bool_as_contiguous(arrays: Vec<&BoolArray>) -> VortexResult<BoolArray> {
// 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<BoolArray> {
))
}

fn primitive_as_contiguous(arrays: Vec<&PrimitiveArray>) -> EncResult<PrimitiveArray> {
fn primitive_as_contiguous(arrays: Vec<&PrimitiveArray>) -> VortexResult<PrimitiveArray> {
if !arrays.iter().map(|chunk| (*chunk).ptype()).all_equal() {
return Err(VortexError::ComputeError(
"Chunks have differing ptypes".into(),
4 changes: 2 additions & 2 deletions vortex/src/compute/search_sorted.rs
Original file line number Diff line number Diff line change
@@ -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<usize> {
) -> VortexResult<usize> {
let enc_scalar: Box<dyn Scalar> = index.into();
// Convert index into correctly typed Arrow scalar.
let enc_scalar = enc_scalar.cast(indices.dtype())?;
6 changes: 3 additions & 3 deletions vortex/src/compute/take.rs
Original file line number Diff line number Diff line change
@@ -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<ArrayRef>;
fn take(&self, indices: &dyn Array) -> VortexResult<ArrayRef>;
}

pub fn take(array: &dyn Array, indices: &dyn Array) -> EncResult<ArrayRef> {
pub fn take(array: &dyn Array, indices: &dyn Array) -> VortexResult<ArrayRef> {
array
.compute()
.and_then(|c| c.take())
2 changes: 1 addition & 1 deletion vortex/src/error.rs
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ pub enum VortexError {
IndexArrayMustBeStrictSorted,
}

pub type EncResult<T> = Result<T, VortexError>;
pub type VortexResult<T> = Result<T, VortexError>;

// Wrap up external errors so that we can implement a dumb PartialEq
#[derive(Debug)]
6 changes: 3 additions & 3 deletions vortex/src/ptype.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>, Error =VortexError>
+ TryFrom<Box<dyn Scalar>, 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<Self> {
fn try_from(value: &DType) -> VortexResult<Self> {
use Signedness::*;
match value {
DType::Int(w, s, _) => match w {
4 changes: 2 additions & 2 deletions vortex/src/scalar/binary.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, _dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
todo!()
}

8 changes: 4 additions & 4 deletions vortex/src/scalar/bool.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
match dtype {
DType::Bool(Nullability::NonNullable) => Ok(self.clone().boxed()),
DType::Bool(Nullability::Nullable) => {
@@ -77,15 +77,15 @@ impl TryFrom<Box<dyn Scalar>> for bool {
type Error = VortexError;

#[inline]
fn try_from(value: Box<dyn Scalar>) -> EncResult<Self> {
fn try_from(value: Box<dyn Scalar>) -> VortexResult<Self> {
value.as_ref().try_into()
}
}

impl TryFrom<&dyn Scalar> for bool {
type Error = VortexError;

fn try_from(value: &dyn Scalar) -> EncResult<Self> {
fn try_from(value: &dyn Scalar) -> VortexResult<Self> {
if let Some(bool_scalar) = value
.as_nonnull()
.and_then(|v| v.as_any().downcast_ref::<BoolScalar>())
10 changes: 6 additions & 4 deletions vortex/src/scalar/list.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
match dtype {
DType::List(field_dtype, n) => {
let new_fields: Vec<Box<dyn Scalar>> = self
@@ -96,7 +96,7 @@ impl<T: Into<Box<dyn Scalar>>> From<ListScalarVec<T>> for Box<dyn Scalar> {
}
}

impl<T: TryFrom<Box<dyn Scalar>, Error =VortexError>> TryFrom<&dyn Scalar> for ListScalarVec<T> {
impl<T: TryFrom<Box<dyn Scalar>, Error = VortexError>> TryFrom<&dyn Scalar> for ListScalarVec<T> {
type Error = VortexError;

fn try_from(value: &dyn Scalar) -> Result<Self, Self::Error> {
@@ -115,7 +115,9 @@ impl<T: TryFrom<Box<dyn Scalar>, Error =VortexError>> TryFrom<&dyn Scalar> for L
}
}

impl<T: TryFrom<Box<dyn Scalar>, Error =VortexError>> TryFrom<Box<dyn Scalar>> for ListScalarVec<T> {
impl<T: TryFrom<Box<dyn Scalar>, Error = VortexError>> TryFrom<Box<dyn Scalar>>
for ListScalarVec<T>
{
type Error = VortexError;

fn try_from(value: Box<dyn Scalar>) -> Result<Self, Self::Error> {
4 changes: 2 additions & 2 deletions vortex/src/scalar/localtime.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, _dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
todo!()
}

4 changes: 2 additions & 2 deletions vortex/src/scalar/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>>;
fn cast(&self, dtype: &DType) -> VortexResult<Box<dyn Scalar>>;

fn nbytes(&self) -> usize;
}
4 changes: 2 additions & 2 deletions vortex/src/scalar/null.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
Ok(NullableScalar::none(dtype.clone()).boxed())
}

8 changes: 4 additions & 4 deletions vortex/src/scalar/nullable.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, _dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
todo!()
}

@@ -99,7 +99,7 @@ impl<T: Into<Box<dyn Scalar>>> From<NullableScalarOption<T>> for Box<dyn Scalar>
}
}

impl<T: TryFrom<Box<dyn Scalar>, Error =VortexError>> TryFrom<&dyn Scalar>
impl<T: TryFrom<Box<dyn Scalar>, Error = VortexError>> TryFrom<&dyn Scalar>
for NullableScalarOption<T>
{
type Error = VortexError;
@@ -116,7 +116,7 @@ impl<T: TryFrom<Box<dyn Scalar>, Error =VortexError>> TryFrom<&dyn Scalar>
}
}

impl<T: TryFrom<Box<dyn Scalar>, Error =VortexError>> TryFrom<Box<dyn Scalar>>
impl<T: TryFrom<Box<dyn Scalar>, Error = VortexError>> TryFrom<Box<dyn Scalar>>
for NullableScalarOption<T>
{
type Error = VortexError;
22 changes: 12 additions & 10 deletions vortex/src/scalar/primitive.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
pub fn cast_dtype(&self, dtype: DType) -> VortexResult<Box<dyn Scalar>> {
macro_rules! from_int {
($dtype:ident , $ps:ident) => {
match $dtype {
@@ -64,7 +64,7 @@ impl PScalar {
}
}

pub fn cast_ptype(&self, ptype: PType) -> EncResult<Box<dyn Scalar>> {
pub fn cast_ptype(&self, ptype: PType) -> VortexResult<Box<dyn Scalar>> {
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<Box<dyn Scalar>> {
let ptype: EncResult<PType> = dtype.try_into();
fn cast(&self, dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
let ptype: VortexResult<PType> = dtype.try_into();
ptype
.and_then(|p| self.cast_ptype(p))
.or_else(|_| self.cast_dtype(dtype.clone()))
@@ -176,15 +176,15 @@ macro_rules! pscalar {
type Error = VortexError;

#[inline]
fn try_from(value: Box<dyn Scalar>) -> EncResult<Self> {
fn try_from(value: Box<dyn Scalar>) -> VortexResult<Self> {
value.as_ref().try_into()
}
}

impl TryFrom<&dyn Scalar> for $T {
type Error = VortexError;

fn try_from(value: &dyn Scalar) -> EncResult<Self> {
fn try_from(value: &dyn Scalar) -> VortexResult<Self> {
if let Some(pscalar) = value
.as_nonnull()
.and_then(|v| v.as_any().downcast_ref::<PScalar>())
@@ -223,15 +223,15 @@ impl From<usize> for Box<dyn Scalar> {
impl TryFrom<Box<dyn Scalar>> for usize {
type Error = VortexError;

fn try_from(value: Box<dyn Scalar>) -> EncResult<Self> {
fn try_from(value: Box<dyn Scalar>) -> VortexResult<Self> {
value.as_ref().try_into()
}
}

impl TryFrom<&dyn Scalar> for usize {
type Error = VortexError;

fn try_from(value: &dyn Scalar) -> EncResult<Self> {
fn try_from(value: &dyn Scalar) -> VortexResult<Self> {
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<dyn Scalar> = (-10i16).into();
assert_eq!(
scalar.as_ref().try_into(),
Err::<usize, VortexError>(VortexError::ComputeError("required positive integer".into()))
Err::<usize, VortexError>(VortexError::ComputeError(
"required positive integer".into()
))
);
}

4 changes: 2 additions & 2 deletions vortex/src/scalar/struct_.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
match dtype {
DType::Struct(names, field_dtypes) => {
if field_dtypes.len() != self.values.len() {
4 changes: 2 additions & 2 deletions vortex/src/scalar/utf8.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Scalar>> {
fn cast(&self, _dtype: &DType) -> VortexResult<Box<dyn Scalar>> {
todo!()
}

15 changes: 9 additions & 6 deletions vortex/src/stats.rs
Original file line number Diff line number Diff line change
@@ -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<T: TryFrom<Box<dyn Scalar>, Error =VortexError>>(
fn get_as<T: TryFrom<Box<dyn Scalar>, Error = VortexError>>(
&self,
stat: &Stat,
) -> EncResult<Option<T>> {
) -> VortexResult<Option<T>> {
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<T: TryFrom<Box<dyn Scalar>, Error =VortexError>>(&self, stat: &Stat) -> Option<T> {
pub fn get_as<T: TryFrom<Box<dyn Scalar>, Error = VortexError>>(
&self,
stat: &Stat,
) -> Option<T> {
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<T: TryFrom<Box<dyn Scalar>, Error =VortexError>>(
pub fn get_or_compute_as<T: TryFrom<Box<dyn Scalar>, Error = VortexError>>(
&self,
stat: &Stat,
) -> Option<T> {
self.get_or_compute(stat).map(|v| T::try_from(v).unwrap())
}

pub fn get_or_compute_or<T: TryFrom<Box<dyn Scalar>, Error =VortexError>>(
pub fn get_or_compute_or<T: TryFrom<Box<dyn Scalar>, Error = VortexError>>(
&self,
default: T,
stat: &Stat,

0 comments on commit 9464dbb

Please sign in to comment.