Skip to content

Commit

Permalink
Resolve merge conflits and utilize new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGS committed Jun 24, 2024
1 parent 78d0f37 commit 4d8ee5f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
48 changes: 20 additions & 28 deletions encodings/byte_bool/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl SliceFn for ByteBoolArray {
impl TakeFn for ByteBoolArray {
fn take(&self, indices: &Array) -> VortexResult<Array> {
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 {
Expand Down Expand Up @@ -129,9 +129,9 @@ impl TakeFn for ByteBoolArray {

impl CompareFn for ByteBoolArray {
fn compare(&self, other: &Array, op: Operator) -> VortexResult<Array> {
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(),
Expand All @@ -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);
Expand Down Expand Up @@ -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 _,
};

Expand Down Expand Up @@ -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));
}
}
Expand All @@ -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));
}
}
Expand All @@ -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());
}
}
8 changes: 4 additions & 4 deletions encodings/byte_bool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,12 +89,12 @@ impl ArrayTrait for ByteBoolArray {
}
}

impl ArrayFlatten for ByteBoolArray {
fn flatten(self) -> VortexResult<Flattened> {
impl IntoCanonical for ByteBoolArray {
fn into_canonical(self) -> VortexResult<Canonical> {
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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions encodings/byte_bool/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use vortex::{
stats::{ArrayStatisticsCompute, Stat, StatsSet},
ArrayTrait, AsArray,
ArrayTrait, AsArray, IntoCanonical,
};
use vortex_error::VortexResult;

Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/bool/compute/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait CompareFn {

pub fn compare(left: &Array, right: &Array, operator: Operator) -> VortexResult<Array> {
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;
}
Expand Down
4 changes: 4 additions & 0 deletions vortex-scalar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 4d8ee5f

Please sign in to comment.