Skip to content
Open
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
19 changes: 19 additions & 0 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod tests {
use vortex_array::VortexSessionExecute;
use vortex_array::array_session;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::compute::conformance::binary_numeric::test_binary_numeric_array;
use vortex_array::compute::conformance::consistency::test_array_consistency;
use vortex_array::dtype::DecimalDType;
use vortex_buffer::buffer;
Expand Down Expand Up @@ -74,4 +75,22 @@ mod tests {
let ctx = &mut array_session().create_execution_ctx();
test_array_consistency(&array.into_array(), ctx);
}

#[rstest]
#[case::decimal_i32(DecimalByteParts::try_new(
buffer![100i32, 200, 300, 400, 500].into_array(),
DecimalDType::new(10, 2)
).unwrap())]
#[case::decimal_nullable_i64(DecimalByteParts::try_new(
PrimitiveArray::from_option_iter([Some(1000i64), None, Some(3000), Some(4000), None]).into_array(),
DecimalDType::new(19, 4)
).unwrap())]
#[case::decimal_negative(DecimalByteParts::try_new(
buffer![-100i32, -200, 300, -400, 500].into_array(),
DecimalDType::new(10, 2)
).unwrap())]
fn test_decimal_byte_parts_binary_numeric(#[case] array: DecimalBytePartsArray) {
let ctx = &mut array_session().create_execution_ctx();
test_binary_numeric_array(&array.into_array(), ctx);
}
}
33 changes: 33 additions & 0 deletions vortex-array/benches/binary_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use vortex_array::VortexSessionExecute;
use vortex_array::array_session;
use vortex_array::arrays::BoolArray;
use vortex_array::arrays::ConstantArray;
use vortex_array::arrays::DecimalArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DecimalDType;
use vortex_array::scalar_fn::fns::operators::Operator;
use vortex_session::VortexSession;

Expand Down Expand Up @@ -136,6 +138,22 @@ fn sub_i64_constant(bencher: Bencher) {
bench_primitive(bencher, lhs, rhs, Operator::Sub);
}

#[divan::bench]
fn add_decimal_i64_nonnull(bencher: Bencher) {
let lhs = decimal_i64_nonnull(0).into_array();
let rhs = decimal_i64_nonnull(1_000_000).into_array();

bench_decimal(bencher, lhs, rhs, Operator::Add);
}

#[divan::bench]
fn add_decimal_i128_nullable(bencher: Bencher) {
let lhs = decimal_i128_nullable(0, 7).into_array();
let rhs = decimal_i128_nullable(1_000_000, 5).into_array();

bench_decimal(bencher, lhs, rhs, Operator::Add);
}

#[divan::bench]
fn eq_i64_constant(bencher: Bencher) {
let lhs = primitive_nonnull(0).into_array();
Expand Down Expand Up @@ -172,6 +190,10 @@ fn bench_primitive(bencher: Bencher, lhs: ArrayRef, rhs: ArrayRef, operator: Ope
bench_binary::<PrimitiveArray>(bencher, lhs, rhs, operator);
}

fn bench_decimal(bencher: Bencher, lhs: ArrayRef, rhs: ArrayRef, operator: Operator) {
bench_binary::<DecimalArray>(bencher, lhs, rhs, operator);
}

fn bench_bool(bencher: Bencher, lhs: ArrayRef, rhs: ArrayRef, operator: Operator) {
bench_binary::<BoolArray>(bencher, lhs, rhs, operator);
}
Expand All @@ -197,6 +219,17 @@ fn primitive_nonnull(base: i64) -> PrimitiveArray {
PrimitiveArray::from_iter((0..LEN as i64).map(|i| base + i))
}

fn decimal_i64_nonnull(base: i64) -> DecimalArray {
DecimalArray::from_iter::<i64, _>((0..LEN as i64).map(|i| base + i), DecimalDType::new(18, 2))
}

fn decimal_i128_nullable(base: i128, null_every: usize) -> DecimalArray {
DecimalArray::from_option_iter::<i128, _>(
(0..LEN as i128).map(|i| (!(i as usize).is_multiple_of(null_every)).then_some(base + i)),
DecimalDType::new(38, 2),
)
}

fn primitive_small_nonnull(offset: i64) -> PrimitiveArray {
PrimitiveArray::from_iter((0..LEN as i64).map(|i| ((i + offset) % 1024) + 1))
}
Expand Down
9 changes: 9 additions & 0 deletions vortex-array/src/arrays/chunked/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ mod tests {
use crate::VortexSessionExecute;
use crate::array_session;
use crate::arrays::ChunkedArray;
use crate::arrays::DecimalArray;
use crate::arrays::PrimitiveArray;
use crate::compute::conformance::binary_numeric::test_binary_numeric_array;
use crate::compute::conformance::consistency::test_array_consistency;
use crate::dtype::DType;
use crate::dtype::DecimalDType;
use crate::dtype::Nullability;
use crate::dtype::PType;

Expand Down Expand Up @@ -158,6 +160,13 @@ mod tests {
],
DType::Primitive(PType::I32, Nullability::NonNullable),
).unwrap())]
#[case::chunked_decimal(ChunkedArray::try_new(
vec![
DecimalArray::from_iter::<i64, _>([100, 250], DecimalDType::new(10, 2)).into_array(),
DecimalArray::from_iter::<i64, _>([300, 400, 500], DecimalDType::new(10, 2)).into_array(),
],
DType::Decimal(DecimalDType::new(10, 2), Nullability::NonNullable),
).unwrap())]
fn test_chunked_binary_numeric(#[case] array: ChunkedArray) {
test_binary_numeric_array(
&array.into_array(),
Expand Down
58 changes: 58 additions & 0 deletions vortex-array/src/arrays/decimal/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ mod tests {
use crate::VortexSessionExecute;
use crate::array_session;
use crate::arrays::DecimalArray;
use crate::compute::conformance::binary_numeric::test_binary_numeric_array;
use crate::compute::conformance::consistency::test_array_consistency;
use crate::dtype::DecimalDType;
use crate::dtype::NativeDecimalType;
use crate::validity::Validity;

#[rstest]
Expand Down Expand Up @@ -60,4 +62,60 @@ mod tests {
&mut array_session().create_execution_ctx(),
);
}

#[rstest]
#[case::decimal_array(DecimalArray::new(
buffer![100i128, 200i128, 300i128, 400i128, 500i128],
DecimalDType::new(19, 2),
Validity::NonNullable,
))]
#[case::decimal_nullable(DecimalArray::new(
buffer![1000i128, 2000i128, 3000i128, 4000i128, 5000i128],
DecimalDType::new(19, 3),
Validity::from_iter([true, false, true, true, false]),
))]
#[case::decimal_small_precision(DecimalArray::new(
buffer![10i128, 20i128, 30i128],
DecimalDType::new(5, 1),
Validity::NonNullable,
))]
#[case::decimal_narrow_storage(DecimalArray::new(
buffer![10i8, 20i8, 30i8],
DecimalDType::new(5, 1),
Validity::NonNullable,
))]
#[case::decimal_widened_carry(DecimalArray::new(
buffer![
<i128 as NativeDecimalType>::MAX_BY_PRECISION[38],
<i128 as NativeDecimalType>::MIN_BY_PRECISION[38],
],
DecimalDType::new(38, 0),
Validity::NonNullable,
))]
#[case::decimal_single(DecimalArray::new(
buffer![42i128],
DecimalDType::new(10, 0),
Validity::NonNullable,
))]
#[case::decimal_large_scale(DecimalArray::new(
buffer![123456789012345i128, 987654321098765i128],
DecimalDType::new(20, 10),
Validity::NonNullable,
))]
#[case::decimal_negative(DecimalArray::new(
buffer![-100i128, -200i128, 300i128, -400i128],
DecimalDType::new(10, 2),
Validity::NonNullable,
))]
#[case::decimal_negative_scale(DecimalArray::new(
buffer![5i64, -3i64, 600i64],
DecimalDType::new(10, -2),
Validity::NonNullable,
))]
fn test_decimal_binary_numeric(#[case] array: DecimalArray) {
test_binary_numeric_array(
&array.into_array(),
&mut array_session().create_execution_ctx(),
);
}
}
19 changes: 19 additions & 0 deletions vortex-array/src/arrays/decimal/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@

use itertools::Itertools;
use itertools::MinMaxResult;
use vortex_buffer::Buffer;
use vortex_error::VortexExpect;

use crate::arrays::DecimalArray;
use crate::arrays::decimal::DecimalArrayExt;
use crate::dtype::DecimalType;
use crate::dtype::NativeDecimalType;
use crate::dtype::i256;
use crate::match_each_decimal_value_type;

/// Return the array's unscaled values widened to `W`, which must be at least as wide as the
/// array's storage type.
pub(crate) fn widened_buffer<W: NativeDecimalType>(array: &DecimalArray) -> Buffer<W> {
if array.values_type() == W::DECIMAL_TYPE {
return array.buffer::<W>();
}
match_each_decimal_value_type!(array.values_type(), |T| {
array
.buffer::<T>()
.iter()
.map(|v| W::from(*v).vortex_expect("widening decimal cast must succeed"))
.collect()
})
}

macro_rules! try_downcast {
($array:expr, from: $src:ty, to: $($dst:ty),*) => {{
Expand Down
Loading
Loading