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
34 changes: 29 additions & 5 deletions encodings/sequence/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use vortex_array::arrays::PrimitiveArray;
use vortex_array::buffer::BufferHandle;
use vortex_array::expr::stats::Precision as StatPrecision;
use vortex_array::expr::stats::Stat;
use vortex_array::match_each_pvalue;
use vortex_array::scalar::PValue;
use vortex_array::scalar::Scalar;
use vortex_array::scalar::ScalarValue;
Expand Down Expand Up @@ -133,11 +134,13 @@ impl SequenceArray {

// A sequence A[i] = base + i * multiplier is sorted iff multiplier >= 0,
// and strictly sorted iff multiplier > 0.
let m_int = multiplier
.cast::<i64>()
.vortex_expect("must be able to cast");
let is_sorted = m_int >= 0;
let is_strict_sorted = m_int > 0;

let (is_sorted, is_strict_sorted) = match_each_pvalue!(
multiplier,
uint: |v| { (true, v> 0) },
int: |v| { (v >= 0, v > 0) },
float: |_v| { unreachable!("float multiplier not supported") }
);

// SAFETY: we don't have duplicate stats
let stats_set = unsafe {
Expand Down Expand Up @@ -521,4 +524,25 @@ mod tests {
assert_eq!(is_strict_sorted, Some(StatPrecision::Exact(false)));
Ok(())
}

// This is regression test for an issue caught by the fuzzer, where SequenceArrays with
// multiplier > i64::MAX were unable to be constructed.
#[test]
fn test_large_multiplier_sorted() -> VortexResult<()> {
let large_multiplier = (i64::MAX as u64) + 1;
let arr = SequenceArray::typed_new(0, large_multiplier, Nullability::NonNullable, 2)?;

let is_sorted = arr
.statistics()
.with_typed_stats_set(|s| s.get_as::<bool>(Stat::IsSorted));

let is_strict_sorted = arr
.statistics()
.with_typed_stats_set(|s| s.get_as::<bool>(Stat::IsStrictSorted));

assert_eq!(is_sorted, Some(StatPrecision::Exact(true)));
assert_eq!(is_strict_sorted, Some(StatPrecision::Exact(true)));

Ok(())
}
}
2 changes: 2 additions & 0 deletions vortex-array/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14578,6 +14578,8 @@ pub fn vortex_array::vtable::validity_to_child(validity: &vortex_array::validity

pub type vortex_array::vtable::ArrayId = arcref::ArcRef<str>

pub macro vortex_array::match_each_pvalue!

pub macro vortex_array::register_kernel!

pub macro vortex_array::vtable!
Expand Down
62 changes: 62 additions & 0 deletions vortex-array/src/scalar/typed_view/primitive/pvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,68 @@ use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;

/// Utility macro that makes it easy to write expressions generic over the different `PValue`
/// variants.
#[macro_export]
macro_rules! match_each_pvalue {
(
$this:expr,uint: |
$vuint:ident |
$buint:block,int: |
$vint:ident |
$bint:block,float: |
$vfloat:ident |
$bfloat:block
) => {{
match $this {
PValue::U8(x) => {
let $vuint = x;
$buint
}
PValue::U16(x) => {
let $vuint = x;
$buint
}
PValue::U32(x) => {
let $vuint = x;
$buint
}
PValue::U64(x) => {
let $vuint = x;
$buint
}
PValue::I8(x) => {
let $vint = x;
$bint
}
PValue::I16(x) => {
let $vint = x;
$bint
}
PValue::I32(x) => {
let $vint = x;
$bint
}
PValue::I64(x) => {
let $vint = x;
$bint
}
PValue::F16(x) => {
let $vfloat = x;
$bfloat
}
PValue::F32(x) => {
let $vfloat = x;
$bfloat
}
PValue::F64(x) => {
let $vfloat = x;
$bfloat
}
}
}};
}

/// A primitive value that can represent any primitive type supported by Vortex.
///
/// `PValue` is used to store primitive scalar values in a type-erased manner,
Expand Down
Loading