Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use num_traits::NumCast;
use vortex_array::arrays::ConstantArray;
use vortex_array::compute::{CompareKernel, CompareKernelAdapter, Operator, compare};
use vortex_array::{Array, ArrayRef, register_kernel};
use vortex_dtype::{IntegerPType, Nullability, PType, ToI256, match_each_integer_ptype};
use vortex_dtype::{
IntegerPType, Nullability, PType, ToI256, match_each_decimal_value, match_each_integer_ptype,
};
use vortex_error::{VortexExpect, VortexResult};
use vortex_scalar::{DecimalValue, Scalar, ScalarValue, match_each_decimal_value};
use vortex_scalar::{DecimalValue, Scalar, ScalarValue};

use crate::DecimalBytePartsVTable;
use crate::decimal_byte_parts::compute::compare::Sign::Positive;
Expand Down
6 changes: 2 additions & 4 deletions encodings/sparse/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ use vortex_array::{Array, Canonical, ToCanonical};
use vortex_buffer::{BitBuffer, Buffer, BufferString, ByteBuffer, buffer, buffer_mut};
use vortex_dtype::{
DType, DecimalDType, DecimalType, IntegerPType, NativeDecimalType, NativePType, Nullability,
StructFields, match_each_integer_ptype, match_each_native_ptype,
StructFields, match_each_decimal_value_type, match_each_integer_ptype, match_each_native_ptype,
};
use vortex_error::{VortexError, VortexExpect, vortex_panic};
use vortex_scalar::{
DecimalScalar, ListScalar, Scalar, StructScalar, match_each_decimal_value_type,
};
use vortex_scalar::{DecimalScalar, ListScalar, Scalar, StructScalar};

use crate::{SparseArray, SparseVTable};

Expand Down
6 changes: 4 additions & 2 deletions fuzz/src/array/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ use vortex_array::compute::{Operator, scalar_cmp};
use vortex_array::validity::Validity;
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
use vortex_buffer::BitBuffer;
use vortex_dtype::{DType, NativeDecimalType, NativePType, match_each_native_ptype};
use vortex_dtype::{
DType, NativeDecimalType, NativePType, match_each_decimal_value_type, match_each_native_ptype,
};
use vortex_error::{VortexExpect, VortexResult, vortex_err};
use vortex_scalar::{Scalar, match_each_decimal_value_type};
use vortex_scalar::Scalar;

pub fn compare_canonical_array(
array: &dyn Array,
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/array/fill_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use vortex_array::validity::Validity;
use vortex_array::vtable::ValidityHelper;
use vortex_array::{ArrayRef, Canonical, IntoArray, ToCanonical};
use vortex_buffer::Buffer;
use vortex_dtype::{DType, Nullability, match_each_native_ptype};
use vortex_dtype::{DType, Nullability, match_each_decimal_value_type, match_each_native_ptype};
use vortex_error::{VortexExpect, VortexResult, VortexUnwrap};
use vortex_scalar::{Scalar, match_each_decimal_value_type};
use vortex_scalar::Scalar;

/// Apply fill_null on the canonical form of the array to get a consistent baseline.
/// This implementation manually fills null values for each canonical type
Expand Down
3 changes: 1 addition & 2 deletions fuzz/src/array/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use vortex_array::arrays::{BoolArray, DecimalArray, PrimitiveArray, StructArray,
use vortex_array::validity::Validity;
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
use vortex_buffer::{BitBuffer, Buffer};
use vortex_dtype::{DType, match_each_native_ptype};
use vortex_dtype::{DType, match_each_decimal_value_type, match_each_native_ptype};
use vortex_error::VortexResult;
use vortex_scalar::match_each_decimal_value_type;

use crate::array::take_canonical_array_non_nullable_indices;

Expand Down
3 changes: 1 addition & 2 deletions fuzz/src/array/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ use vortex_array::arrays::{
use vortex_array::validity::Validity;
use vortex_array::vtable::ValidityHelper;
use vortex_array::{ArrayRef, Canonical, IntoArray, ToCanonical};
use vortex_dtype::ExtDType;
use vortex_dtype::{ExtDType, match_each_decimal_value_type};
use vortex_error::{VortexResult, VortexUnwrap};
use vortex_mask::{AllOr, Mask};
use vortex_scalar::match_each_decimal_value_type;

/// Apply mask on the canonical form of the array to get a consistent baseline.
/// This implementation manually applies the mask to each canonical type
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/array/scalar_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::sync::Arc;

use vortex_array::arrays::varbin_scalar;
use vortex_array::{Array, Canonical};
use vortex_dtype::{DType, match_each_native_ptype};
use vortex_dtype::{DType, match_each_decimal_value_type, match_each_native_ptype};
use vortex_error::{VortexResult, VortexUnwrap};
use vortex_scalar::{DecimalValue, Scalar, match_each_decimal_value_type};
use vortex_scalar::{DecimalValue, Scalar};

/// Baseline implementation of scalar_at that works on canonical arrays.
/// This implementation manually extracts the scalar value from each canonical type
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/array/search_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use vortex_array::accessor::ArrayAccessor;
use vortex_array::search_sorted::{IndexOrd, SearchResult, SearchSorted, SearchSortedSide};
use vortex_array::{Array, ToCanonical};
use vortex_buffer::{BufferString, ByteBuffer};
use vortex_dtype::{DType, NativePType, match_each_native_ptype};
use vortex_dtype::{DType, NativePType, match_each_decimal_value_type, match_each_native_ptype};
use vortex_error::{VortexResult, vortex_err};
use vortex_scalar::{Scalar, match_each_decimal_value_type};
use vortex_scalar::Scalar;

struct SearchNullableSlice<T>(Vec<Option<T>>);

Expand Down
3 changes: 1 addition & 2 deletions fuzz/src/array/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use vortex_array::arrays::{
};
use vortex_array::validity::Validity;
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
use vortex_dtype::{DType, match_each_native_ptype};
use vortex_dtype::{DType, match_each_decimal_value_type, match_each_native_ptype};
use vortex_error::VortexResult;
use vortex_scalar::match_each_decimal_value_type;

#[allow(clippy::unnecessary_fallible_conversions)]
pub fn slice_canonical_array(
Expand Down
3 changes: 1 addition & 2 deletions fuzz/src/array/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use std::cmp::Ordering;
use vortex_array::accessor::ArrayAccessor;
use vortex_array::arrays::{BoolArray, DecimalArray, PrimitiveArray, VarBinViewArray};
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
use vortex_dtype::{DType, NativePType, match_each_native_ptype};
use vortex_dtype::{DType, NativePType, match_each_decimal_value_type, match_each_native_ptype};
use vortex_error::{VortexExpect, VortexResult};
use vortex_scalar::match_each_decimal_value_type;

use crate::array::take_canonical_array_non_nullable_indices;

Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/array/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use vortex_array::validity::Validity;
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
use vortex_buffer::Buffer;
use vortex_dtype::{
DType, DecimalDType, NativeDecimalType, NativePType, Nullability, match_each_native_ptype,
DType, DecimalDType, NativeDecimalType, NativePType, Nullability,
match_each_decimal_value_type, match_each_native_ptype,
};
use vortex_error::{VortexExpect, VortexResult};
use vortex_scalar::match_each_decimal_value_type;

pub fn take_canonical_array_non_nullable_indices(
array: &dyn Array,
Expand Down
6 changes: 4 additions & 2 deletions vortex-array/src/arrays/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use std::sync::Arc;

use arbitrary::{Arbitrary, Result, Unstructured};
use vortex_buffer::{BitBuffer, Buffer};
use vortex_dtype::{DType, IntegerPType, NativePType, Nullability, PType};
use vortex_dtype::{
DType, IntegerPType, NativePType, Nullability, PType, match_each_decimal_value_type,
};
use vortex_error::{VortexExpect, VortexUnwrap};
use vortex_scalar::Scalar;
use vortex_scalar::arbitrary::random_scalar;
use vortex_scalar::{Scalar, match_each_decimal_value_type};

use super::{BoolArray, ChunkedArray, NullArray, PrimitiveArray, StructArray};
use crate::arrays::{VarBinArray, VarBinViewArray};
Expand Down
8 changes: 5 additions & 3 deletions vortex-array/src/arrays/constant/vtable/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
use std::sync::Arc;

use vortex_buffer::{BitBuffer, Buffer, buffer};
use vortex_dtype::{DType, DecimalType, Nullability, match_each_native_ptype};
use vortex_dtype::{
DType, DecimalType, Nullability, match_each_decimal_value, match_each_decimal_value_type,
match_each_native_ptype,
};
use vortex_error::VortexExpect;
use vortex_scalar::{
BinaryScalar, BoolScalar, DecimalValue, ExtScalar, ListScalar, Scalar, StructScalar,
Utf8Scalar, match_each_decimal_value, match_each_decimal_value_type,
BinaryScalar, BoolScalar, DecimalValue, ExtScalar, ListScalar, Scalar, StructScalar, Utf8Scalar,
};

use crate::arrays::binary_view::BinaryView;
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/constant/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod array;
mod canonical;
mod encode;
mod operations;
mod pipeline;
mod operator;
mod serde;
mod validity;
mod visitor;
Expand Down
109 changes: 109 additions & 0 deletions vortex-array/src/arrays/constant/vtable/operator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use vortex_dtype::{
DType, DecimalType, PrecisionScale, match_each_decimal_value_type, match_each_native_ptype,
};
use vortex_error::{VortexExpect, VortexResult};
use vortex_scalar::{BinaryScalar, BoolScalar, DecimalScalar, PrimitiveScalar, Scalar, Utf8Scalar};
use vortex_vector::binaryview::{BinaryVectorMut, StringVectorMut};
use vortex_vector::bool::BoolVectorMut;
use vortex_vector::decimal::{DVectorMut, DecimalVectorMut};
use vortex_vector::null::NullVectorMut;
use vortex_vector::primitive::{PVectorMut, PrimitiveVectorMut};
use vortex_vector::{VectorMut, VectorMutOps};

use crate::ArrayRef;
use crate::arrays::{ConstantArray, ConstantVTable};
use crate::execution::{BatchKernelRef, BindCtx, kernel};
use crate::vtable::OperatorVTable;

impl OperatorVTable<ConstantVTable> for ConstantVTable {
fn bind(
array: &ConstantArray,
selection: Option<&ArrayRef>,
ctx: &mut dyn BindCtx,
) -> VortexResult<BatchKernelRef> {
let mask = ctx.bind_selection(array.len, selection)?;
let scalar = array.scalar().clone();

Ok(kernel(move || {
// TODO(ngates): would be good to do a sum aggregation, rather than execution.
let mask = mask.execute()?;
Ok(to_vector(scalar, mask.true_count()).freeze())
}))
}
}

fn to_vector(scalar: Scalar, len: usize) -> VectorMut {
match scalar.dtype() {
DType::Null => NullVectorMut::new(len).into(),
DType::Bool(_) => to_vector_bool(scalar.as_bool(), len).into(),
DType::Primitive(..) => to_vector_primitive(scalar.as_primitive(), len).into(),
DType::Decimal(..) => to_vector_decimal(scalar.as_decimal(), len).into(),
DType::Utf8(_) => to_vector_utf8(scalar.as_utf8(), len).into(),
DType::Binary(_) => to_vector_binary(scalar.as_binary(), len).into(),
DType::List(..) => unimplemented!("List constant vectorization"),
DType::FixedSizeList(..) => unimplemented!("FixedSizeList constant vectorization"),
DType::Struct(..) => unimplemented!("Struct constant vectorization"),
DType::Extension(_) => to_vector(scalar.as_extension().storage(), len),
}
}

fn to_vector_bool(scalar: BoolScalar, len: usize) -> BoolVectorMut {
let mut vec = BoolVectorMut::with_capacity(len);
match scalar.value() {
Some(v) => vec.append_values(v, len),
None => vec.append_nulls(len),
}
vec
}

fn to_vector_primitive(scalar: PrimitiveScalar, len: usize) -> PrimitiveVectorMut {
match_each_native_ptype!(scalar.ptype(), |T| {
let mut vec = PVectorMut::<T>::with_capacity(len);
match scalar.typed_value::<T>() {
Some(v) => vec.append_values(v, len),
None => vec.append_nulls(len),
}
vec.into()
})
}

fn to_vector_decimal(scalar: DecimalScalar, len: usize) -> DecimalVectorMut {
let decimal_dtype = scalar
.dtype()
.as_decimal_opt()
.vortex_expect("Decimal scalar must have a decimal type");
let decimal_type = DecimalType::smallest_decimal_value_type(decimal_dtype);

match_each_decimal_value_type!(decimal_type, |D| {
let ps = PrecisionScale::<D>::new(decimal_dtype.precision(), decimal_dtype.scale());
let mut vec = DVectorMut::<D>::with_capacity(ps, len);
match scalar.decimal_value() {
Some(v) => vec
.try_append_n(v.cast::<D>().vortex_expect("known to fit"), len)
.vortex_expect("known to fit"),
None => vec.append_nulls(len),
}
vec.into()
})
}

fn to_vector_utf8(scalar: Utf8Scalar, len: usize) -> StringVectorMut {
let mut vec = StringVectorMut::with_capacity(len);
match scalar.value() {
Some(v) => vec.append_values(v.as_ref(), len),
None => vec.append_nulls(len),
}
vec
}

fn to_vector_binary(scalar: BinaryScalar, len: usize) -> BinaryVectorMut {
let mut vec = BinaryVectorMut::with_capacity(len);
match scalar.value() {
Some(v) => vec.append_values(v.as_ref(), len),
None => vec.append_nulls(len),
}
vec
}
Loading
Loading