diff --git a/encodings/byte_bool/src/compute/mod.rs b/encodings/byte_bool/src/compute/mod.rs index 89bd14330..d1fa3c825 100644 --- a/encodings/byte_bool/src/compute/mod.rs +++ b/encodings/byte_bool/src/compute/mod.rs @@ -4,18 +4,18 @@ use std::sync::Arc; use arrow_buffer::BooleanBuffer; use num_traits::AsPrimitive; use vortex::validity::Validity; -use vortex::Array; use vortex::ToArrayData; use vortex::{ compute::{ - compare::CompareFn, fill::FillForwardFn, scalar_at::ScalarAtFn, slice::SliceFn, - take::TakeFn, ArrayCompute, + compare::CompareFn, slice::SliceFn, take::TakeFn, unary::fill_forward::FillForwardFn, + unary::scalar_at::ScalarAtFn, ArrayCompute, }, encoding::ArrayEncodingRef, stats::StatsSet, validity::ArrayValidity, ArrayDType, ArrayData, ArrayTrait, IntoArray, }; +use vortex::{Array, IntoCanonical}; use vortex_dtype::{match_each_integer_ptype, Nullability}; use vortex_error::{vortex_bail, VortexResult}; use vortex_expr::Operator; @@ -85,7 +85,7 @@ impl SliceFn for ByteBoolArray { impl TakeFn for ByteBoolArray { fn take(&self, indices: &Array) -> VortexResult { let validity = self.validity(); - let indices = indices.clone().flatten_primitive()?; + let indices = indices.clone().as_primitive(); let bools = self.maybe_null_slice(); let arr = match validity { @@ -129,9 +129,9 @@ impl TakeFn for ByteBoolArray { impl CompareFn for ByteBoolArray { fn compare(&self, other: &Array, op: Operator) -> VortexResult { - let flattened = other.clone().flatten_bool()?; + let canonical = other.clone().into_canonical()?.into_bool()?; let lhs = BooleanBuffer::from(self.maybe_null_slice()); - let rhs = flattened.boolean_buffer(); + let rhs = canonical.boolean_buffer(); let result_buf = match op { Operator::Eq => lhs.bitxor(&rhs).not(), @@ -146,7 +146,7 @@ impl CompareFn for ByteBoolArray { let mut validity = Vec::with_capacity(self.len()); let lhs_validity = self.validity(); - let rhs_validity = flattened.validity(); + let rhs_validity = canonical.validity(); for idx in 0..self.len() { let l = lhs_validity.is_valid(idx); @@ -188,7 +188,7 @@ impl FillForwardFn for ByteBoolArray { #[cfg(test)] mod tests { use vortex::{ - compute::{compare::compare, scalar_at::scalar_at, slice::slice}, + compute::{compare::compare, slice::slice, unary::scalar_at::scalar_at}, AsArray as _, }; @@ -219,14 +219,11 @@ mod tests { let lhs = ByteBoolArray::from(vec![true; 5]); let rhs = ByteBoolArray::from(vec![true; 5]); - let arr = compare(lhs.as_array_ref(), rhs.as_array_ref(), Operator::Eq) - .unwrap() - .flatten_bool() - .unwrap(); + let arr = compare(lhs.as_array_ref(), rhs.as_array_ref(), Operator::Eq).unwrap(); for i in 0..arr.len() { - assert!(arr.is_valid(i)); let s = scalar_at(arr.as_array_ref(), i).unwrap(); + assert!(s.is_valid()); assert_eq!(s.value(), &ScalarValue::Bool(true)); } } @@ -236,14 +233,11 @@ mod tests { let lhs = ByteBoolArray::from(vec![false; 5]); let rhs = ByteBoolArray::from(vec![true; 5]); - let arr = compare(lhs.as_array_ref(), rhs.as_array_ref(), Operator::Eq) - .unwrap() - .flatten_bool() - .unwrap(); + let arr = compare(lhs.as_array_ref(), rhs.as_array_ref(), Operator::Eq).unwrap(); for i in 0..arr.len() { - assert!(arr.is_valid(i)); - let s = scalar_at(arr.as_array_ref(), i).unwrap(); + let s = scalar_at(&arr, i).unwrap(); + assert!(s.is_valid()); assert_eq!(s.value(), &ScalarValue::Bool(false)); } } @@ -253,21 +247,19 @@ mod tests { let lhs = ByteBoolArray::from(vec![true; 5]); let rhs = ByteBoolArray::from(vec![Some(true), Some(true), Some(true), Some(false), None]); - let arr = compare(lhs.as_array_ref(), rhs.as_array_ref(), Operator::Eq) - .unwrap() - .flatten_bool() - .unwrap(); + let arr = compare(lhs.as_array_ref(), rhs.as_array_ref(), Operator::Eq).unwrap(); for i in 0..3 { - assert!(arr.is_valid(i)); - let s = scalar_at(arr.as_array_ref(), i).unwrap(); + let s = scalar_at(&arr, i).unwrap(); + assert!(s.is_valid()); assert_eq!(s.value(), &ScalarValue::Bool(true)); } - assert!(arr.is_valid(3)); - let s = scalar_at(arr.as_array_ref(), 3).unwrap(); + let s = scalar_at(&arr, 3).unwrap(); + assert!(s.is_valid()); assert_eq!(s.value(), &ScalarValue::Bool(false)); - assert!(!arr.is_valid(4)); + let s = scalar_at(&arr, 4).unwrap(); + assert!(s.is_null()); } } diff --git a/encodings/byte_bool/src/lib.rs b/encodings/byte_bool/src/lib.rs index c3cbb601e..2ac8b5432 100644 --- a/encodings/byte_bool/src/lib.rs +++ b/encodings/byte_bool/src/lib.rs @@ -7,8 +7,8 @@ use vortex::{ impl_encoding, validity::{ArrayValidity, LogicalValidity, Validity, ValidityMetadata}, visitor::{AcceptArrayVisitor, ArrayVisitor}, - ArrayFlatten, }; +use vortex::{Canonical, IntoCanonical}; use vortex_buffer::Buffer; mod compute; @@ -89,12 +89,12 @@ impl ArrayTrait for ByteBoolArray { } } -impl ArrayFlatten for ByteBoolArray { - fn flatten(self) -> VortexResult { +impl IntoCanonical for ByteBoolArray { + fn into_canonical(self) -> VortexResult { let boolean_buffer = BooleanBuffer::from(self.maybe_null_slice()); let validity = self.validity(); - BoolArray::try_new(boolean_buffer, validity).map(Flattened::Bool) + BoolArray::try_new(boolean_buffer, validity).map(Canonical::Bool) } } diff --git a/encodings/byte_bool/src/stats.rs b/encodings/byte_bool/src/stats.rs index 15ec5fa68..67cb4ab30 100644 --- a/encodings/byte_bool/src/stats.rs +++ b/encodings/byte_bool/src/stats.rs @@ -1,6 +1,6 @@ use vortex::{ stats::{ArrayStatisticsCompute, Stat, StatsSet}, - ArrayTrait, AsArray, + ArrayTrait, AsArray, IntoCanonical, }; use vortex_error::VortexResult; @@ -12,7 +12,7 @@ impl ArrayStatisticsCompute for ByteBoolArray { return Ok(StatsSet::new()); } - let bools = self.as_array_ref().clone().flatten_bool()?; + let bools = self.as_array_ref().clone().into_canonical()?.into_bool()?; bools.compute_statistics(stat) } } diff --git a/vortex-array/src/array/bool/compute/slice.rs b/vortex-array/src/array/bool/compute/slice.rs index fcad9c66e..6939c41a1 100644 --- a/vortex-array/src/array/bool/compute/slice.rs +++ b/vortex-array/src/array/bool/compute/slice.rs @@ -21,7 +21,7 @@ mod tests { use crate::compute::slice::slice; use crate::validity::ArrayValidity; use crate::ArrayTrait; - use crate::{compute::scalar_at::scalar_at, AsArray}; + use crate::{compute::unary::scalar_at::scalar_at, AsArray}; #[test] fn test_slice() { diff --git a/vortex-array/src/compute/compare.rs b/vortex-array/src/compute/compare.rs index 8ccc1887e..80459f887 100644 --- a/vortex-array/src/compute/compare.rs +++ b/vortex-array/src/compute/compare.rs @@ -10,7 +10,7 @@ pub trait CompareFn { pub fn compare(left: &Array, right: &Array, operator: Operator) -> VortexResult { if let Some(matching_indices) = - left.with_dyn(|lhs| lhs.compare().map(|rhs| rhs.compare(right, predicate))) + left.with_dyn(|lhs| lhs.compare().map(|rhs| rhs.compare(right, operator))) { return matching_indices; } diff --git a/vortex-scalar/src/lib.rs b/vortex-scalar/src/lib.rs index e628c098d..1612839a7 100644 --- a/vortex-scalar/src/lib.rs +++ b/vortex-scalar/src/lib.rs @@ -83,6 +83,10 @@ impl Scalar { self.value } + pub fn is_valid(&self) -> bool { + !self.value.is_null() + } + pub fn is_null(&self) -> bool { self.value.is_null() }