Skip to content

Commit ab9d135

Browse files
committed
Merge branch 'develop' into ji/decimal-builder-decimal-dtype
# Conflicts: # vortex-array/src/arrays/arbitrary.rs
2 parents a6c3c91 + a2496f7 commit ab9d135

File tree

17 files changed

+155
-109
lines changed

17 files changed

+155
-109
lines changed

.github/workflows/fuzz.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on:
88
jobs:
99
io_fuzz:
1010
name: "IO Fuzz"
11-
timeout-minutes: 180
11+
timeout-minutes: 230 # almost 4 hours
1212
runs-on:
1313
- runs-on=${{ github.run_id }}
14-
- family=m8g.2xlarge
14+
- family=m8g.large
1515
- image=ubuntu24-full-arm64
1616
- disk=large
1717
- extras=s3-cache
@@ -44,7 +44,7 @@ jobs:
4444
AWS_ENDPOINT_URL: "https://01e9655179bbec953276890b183039bc.r2.cloudflarestorage.com"
4545
- name: Run fuzzing target
4646
id: fuzz
47-
run: RUST_BACKTRACE=1 cargo +nightly fuzz run file_io -j "$(nproc)" -- -max_total_time=7200
47+
run: RUST_BACKTRACE=1 cargo +nightly fuzz run --release --debug-assertions file_io -- -max_total_time=7200
4848
continue-on-error: true
4949
- name: Archive crash artifacts
5050
uses: actions/upload-artifact@v4
@@ -67,10 +67,10 @@ jobs:
6767

6868
ops_fuzz:
6969
name: "Array Operations Fuzz"
70-
timeout-minutes: 180
70+
timeout-minutes: 230 # almost 4 hours
7171
runs-on:
7272
- runs-on=${{ github.run_id }}
73-
- family=m8g.2xlarge
73+
- family=m8g.large
7474
- image=ubuntu24-full-arm64
7575
- disk=large
7676
- extras=s3-cache
@@ -103,7 +103,7 @@ jobs:
103103
AWS_ENDPOINT_URL: "https://01e9655179bbec953276890b183039bc.r2.cloudflarestorage.com"
104104
- name: Run fuzzing target
105105
id: fuzz
106-
run: RUST_BACKTRACE=1 cargo +nightly fuzz run array_ops -j "$(nproc)" -- -max_total_time=7200
106+
run: RUST_BACKTRACE=1 cargo +nightly fuzz run --release --debug-assertions array_ops -- -max_total_time=7200
107107
continue-on-error: true
108108
- name: Archive crash artifacts
109109
uses: actions/upload-artifact@v4

encodings/sparse/src/canonical.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use num_traits::NumCast;
88
use vortex_array::arrays::binary_view::BinaryView;
99
use vortex_array::arrays::{
1010
BoolArray, ConstantArray, FixedSizeListArray, ListViewArray, NullArray, PrimitiveArray,
11-
StructArray, VarBinViewArray, smallest_decimal_value_type,
11+
StructArray, VarBinViewArray,
1212
};
1313
use vortex_array::builders::{
1414
ArrayBuilder, DecimalBuilder, ListViewBuilder, builder_with_capacity,
@@ -19,8 +19,8 @@ use vortex_array::vtable::{CanonicalVTable, ValidityHelper};
1919
use vortex_array::{Array, Canonical, ToCanonical};
2020
use vortex_buffer::{BitBuffer, Buffer, BufferString, ByteBuffer, buffer, buffer_mut};
2121
use vortex_dtype::{
22-
DType, DecimalDType, IntegerPType, NativeDecimalType, NativePType, Nullability, StructFields,
23-
match_each_integer_ptype, match_each_native_ptype,
22+
DType, DecimalDType, DecimalType, IntegerPType, NativeDecimalType, NativePType, Nullability,
23+
StructFields, match_each_integer_ptype, match_each_native_ptype,
2424
};
2525
use vortex_error::{VortexError, VortexExpect, vortex_panic};
2626
use vortex_scalar::{
@@ -58,7 +58,8 @@ impl CanonicalVTable<SparseVTable> for SparseVTable {
5858
array.len(),
5959
),
6060
DType::Decimal(decimal_dtype, nullability) => {
61-
let canonical_decimal_value_type = smallest_decimal_value_type(decimal_dtype);
61+
let canonical_decimal_value_type =
62+
DecimalType::smallest_decimal_value_type(decimal_dtype);
6263
let fill_value = array.fill_scalar().as_decimal();
6364
match_each_decimal_value_type!(canonical_decimal_value_type, |D| {
6465
canonicalize_sparse_decimal::<D>(

fuzz/src/array/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ fn actions_for_dtype(dtype: &DType) -> HashSet<ActionType> {
381381
[Compress, Slice, Take, Filter, MinMax, Mask, ScalarAt].into()
382382
}
383383
DType::Utf8(_) | DType::Binary(_) => {
384-
// Utf8/Binary supports everything except Sum
385-
// Actions: Compress, Slice, Take, SearchSorted, Filter, Compare, Cast, MinMax, FillNull, Mask, ScalarAt
384+
// Utf8/Binary supports everything except Sum and FillNull
385+
// Actions: Compress, Slice, Take, SearchSorted, Filter, Compare, Cast, MinMax, Mask, ScalarAt
386386
[
387387
Compress,
388388
Slice,
@@ -392,7 +392,6 @@ fn actions_for_dtype(dtype: &DType) -> HashSet<ActionType> {
392392
Compare,
393393
Cast,
394394
MinMax,
395-
FillNull,
396395
Mask,
397396
ScalarAt,
398397
]

fuzz/src/array/scalar_at.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use vortex_scalar::{DecimalValue, Scalar, match_each_decimal_value_type};
1313
/// This implementation manually extracts the scalar value from each canonical type
1414
/// without using the scalar_at method, to serve as an independent baseline for testing.
1515
pub fn scalar_at_canonical_array(canonical: Canonical, index: usize) -> VortexResult<Scalar> {
16+
if canonical.as_ref().is_invalid(index) {
17+
return Ok(Scalar::null(canonical.as_ref().dtype().clone()));
18+
}
1619
Ok(match canonical {
1720
Canonical::Null(_array) => Scalar::null(DType::Null),
1821
Canonical::Bool(array) => {

vortex-array/src/arrays/arbitrary.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use vortex_scalar::arbitrary::random_scalar;
1212
use vortex_scalar::{Scalar, match_each_decimal_value_type};
1313

1414
use super::{BoolArray, ChunkedArray, NullArray, PrimitiveArray, StructArray};
15-
use crate::arrays::{VarBinArray, VarBinViewArray, smallest_decimal_value_type};
15+
use crate::arrays::{VarBinArray, VarBinViewArray};
1616
use crate::builders::{ArrayBuilder, DecimalBuilder, FixedSizeListBuilder, ListViewBuilder};
1717
use crate::validity::Validity;
1818
use crate::{Array, ArrayRef, IntoArray, ToCanonical};
@@ -95,16 +95,20 @@ fn random_array_chunk(
9595
},
9696
DType::Decimal(decimal, n) => {
9797
let elem_len = chunk_len.unwrap_or(u.int_in_range(0..=20)?);
98-
match_each_decimal_value_type!(smallest_decimal_value_type(decimal), |DVT| {
99-
let mut builder = DecimalBuilder::new::<DVT>(*decimal, *n);
100-
for _i in 0..elem_len {
101-
let random_decimal = random_scalar(u, &DType::Decimal(*decimal, *n))?;
102-
builder.append_scalar(&random_decimal).vortex_expect(
103-
"was somehow unable to append a decimal to a decimal builder",
104-
);
98+
match_each_decimal_value_type!(
99+
DecimalType::smallest_decimal_value_type(decimal),
100+
|DVT| {
101+
let mut builder =
102+
DecimalBuilder::new::<DVT>(decimal.precision(), decimal.scale(), *n);
103+
for _i in 0..elem_len {
104+
let random_decimal = random_scalar(u, &DType::Decimal(*decimal, *n))?;
105+
builder.append_scalar(&random_decimal).vortex_expect(
106+
"was somehow unable to append a decimal to a decimal builder",
107+
);
108+
}
109+
Ok(builder.finish())
105110
}
106-
Ok(builder.finish())
107-
})
111+
)
108112
}
109113
DType::Utf8(n) => random_string(u, *n, chunk_len),
110114
DType::Binary(n) => random_bytes(u, *n, chunk_len),

vortex-array/src/arrays/constant/vtable/canonical.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::sync::Arc;
55

66
use vortex_buffer::{BitBuffer, Buffer, buffer};
7-
use vortex_dtype::{DType, Nullability, match_each_native_ptype};
7+
use vortex_dtype::{DType, DecimalType, Nullability, match_each_native_ptype};
88
use vortex_error::VortexExpect;
99
use vortex_scalar::{
1010
BinaryScalar, BoolScalar, DecimalValue, ExtScalar, ListScalar, Scalar, StructScalar,
@@ -16,7 +16,7 @@ use crate::arrays::constant::ConstantArray;
1616
use crate::arrays::primitive::PrimitiveArray;
1717
use crate::arrays::{
1818
BoolArray, ConstantVTable, DecimalArray, ExtensionArray, FixedSizeListArray, ListViewArray,
19-
NullArray, StructArray, VarBinViewArray, smallest_decimal_value_type,
19+
NullArray, StructArray, VarBinViewArray,
2020
};
2121
use crate::builders::builder_with_capacity;
2222
use crate::validity::Validity;
@@ -66,7 +66,7 @@ impl CanonicalVTable<ConstantVTable> for ConstantVTable {
6666
})
6767
}
6868
DType::Decimal(decimal_type, ..) => {
69-
let size = smallest_decimal_value_type(decimal_type);
69+
let size = DecimalType::smallest_decimal_value_type(decimal_type);
7070
let decimal = scalar.as_decimal();
7171
let Some(value) = decimal.decimal_value() else {
7272
let all_null = match_each_decimal_value_type!(size, |D| {

vortex-array/src/arrays/decimal/array.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use vortex_error::{VortexExpect, VortexResult, vortex_ensure, vortex_panic};
1111
use vortex_scalar::match_each_decimal_value_type;
1212

1313
use crate::ToCanonical;
14-
use crate::arrays::is_compatible_decimal_value_type;
1514
use crate::patches::Patches;
1615
use crate::stats::ArrayStats;
1716
use crate::validity::Validity;
@@ -279,7 +278,7 @@ where
279278
PatchDVT: NativeDecimalType,
280279
ValuesDVT: NativeDecimalType,
281280
{
282-
if !is_compatible_decimal_value_type(ValuesDVT::DECIMAL_TYPE, decimal_dtype) {
281+
if !ValuesDVT::DECIMAL_TYPE.is_compatible_decimal_value_type(decimal_dtype) {
283282
vortex_panic!(
284283
"patch_typed: {:?} cannot represent every value in {}.",
285284
ValuesDVT::DECIMAL_TYPE,

vortex-array/src/arrays/decimal/compute/sum.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
use arrow_schema::DECIMAL256_MAX_PRECISION;
55
use num_traits::AsPrimitive;
6-
use vortex_dtype::DecimalDType;
76
use vortex_dtype::Nullability::Nullable;
7+
use vortex_dtype::{DecimalDType, DecimalType};
88
use vortex_error::{VortexResult, vortex_bail};
99
use vortex_mask::Mask;
1010
use vortex_scalar::{DecimalValue, Scalar, match_each_decimal_value_type};
1111

12-
use crate::arrays::{DecimalArray, DecimalVTable, smallest_decimal_value_type};
12+
use crate::arrays::{DecimalArray, DecimalVTable};
1313
use crate::compute::{SumKernel, SumKernelAdapter};
1414
use crate::register_kernel;
1515

@@ -54,7 +54,7 @@ impl SumKernel for DecimalVTable {
5454
vortex_bail!("invalid state, all-null array should be checked by top-level sum fn")
5555
}
5656
Mask::AllTrue(_) => {
57-
let values_type = smallest_decimal_value_type(&return_dtype);
57+
let values_type = DecimalType::smallest_decimal_value_type(&return_dtype);
5858
match_each_decimal_value_type!(array.values_type(), |I| {
5959
match_each_decimal_value_type!(values_type, |O| {
6060
Ok(Scalar::decimal(
@@ -66,7 +66,7 @@ impl SumKernel for DecimalVTable {
6666
})
6767
}
6868
Mask::Values(mask_values) => {
69-
let values_type = smallest_decimal_value_type(&return_dtype);
69+
let values_type = DecimalType::smallest_decimal_value_type(&return_dtype);
7070
match_each_decimal_value_type!(array.values_type(), |I| {
7171
match_each_decimal_value_type!(values_type, |O| {
7272
Ok(Scalar::decimal(

vortex-array/src/arrays/decimal/utils.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,12 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use itertools::{Itertools, MinMaxResult};
5-
use vortex_dtype::DecimalDType;
65
use vortex_error::VortexExpect;
76
use vortex_scalar::{DecimalType, i256};
87

98
use crate::arrays::DecimalArray;
109
use crate::vtable::ValidityHelper;
1110

12-
/// Maps a decimal precision into the smallest type that can represent it.
13-
pub fn smallest_decimal_value_type(decimal_dtype: &DecimalDType) -> DecimalType {
14-
match decimal_dtype.precision() {
15-
1..=2 => DecimalType::I8,
16-
3..=4 => DecimalType::I16,
17-
5..=9 => DecimalType::I32,
18-
10..=18 => DecimalType::I64,
19-
19..=38 => DecimalType::I128,
20-
39..=76 => DecimalType::I256,
21-
0 => unreachable!("precision must be greater than 0"),
22-
p => unreachable!("precision larger than 76 is invalid found precision {p}"),
23-
}
24-
}
25-
26-
/// True if `value_type` can represent every value of the type `dtype`.
27-
pub fn is_compatible_decimal_value_type(value_type: DecimalType, dtype: DecimalDType) -> bool {
28-
value_type >= smallest_decimal_value_type(&dtype)
29-
}
30-
3111
macro_rules! try_downcast {
3212
($array:expr, from: $src:ty, to: $($dst:ty),*) => {{
3313
use vortex_dtype::BigCast;

vortex-array/src/builders/decimal.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::any::Any;
55

66
use vortex_buffer::BufferMut;
77
use vortex_dtype::{BigCast, DType, DecimalDType, NativeDecimalType, Nullability};
8-
use vortex_error::{VortexExpect, VortexResult, vortex_ensure, vortex_panic};
8+
use vortex_error::{
9+
VortexExpect, VortexResult, VortexUnwrap, vortex_ensure, vortex_err, vortex_panic,
10+
};
911
use vortex_mask::Mask;
1012
use vortex_scalar::{
1113
DecimalValue, Scalar, i256, match_each_decimal_value, match_each_decimal_value_type,
@@ -208,7 +210,18 @@ impl ArrayBuilder for DecimalBuilder {
208210
impl DecimalBuffer {
209211
fn push<V: NativeDecimalType>(&mut self, value: V) {
210212
delegate_fn!(self, |T, buffer| {
211-
buffer.push(<T as BigCast>::from(value).vortex_expect("decimal conversion failure"))
213+
buffer.push(
214+
<T as BigCast>::from(value)
215+
.ok_or_else(|| {
216+
vortex_err!(
217+
"decimal conversion failure {:?}, type: {:?} to {:?}",
218+
value,
219+
V::DECIMAL_TYPE,
220+
T::DECIMAL_TYPE,
221+
)
222+
})
223+
.vortex_unwrap(),
224+
)
212225
});
213226
}
214227

0 commit comments

Comments
 (0)