From 06b8535faebd4b2618cd1dae1ec989d20ebf6612 Mon Sep 17 00:00:00 2001 From: Will Manning Date: Sun, 29 Nov 2026 18:43:53 +0000 Subject: [PATCH 1/4] Add Hegel property tests for OnPair, EliasFano, Unary, and ZigZag Wires OnPair, EliasFano (both Primitive and Unary upper representations), Unary, and ZigZag into the shared Hegel encoding harness so serde, scalar probing, comparisons, and chained slice/take/filter/mask ops are checked differentially across generated inputs. Also adds OnPair Hegel coverage for dense repeated Dict takes and Like pushdown across escaped metacharacters and 254-byte state boundaries, replaces the 100k-row Instant::now() smoke test in encodings/onpair/tests/big_data.rs with a compact corpus roundtrip test, and removes the unused num-traits dependency from vortex-zigzag. Authored with AI assistance (Antigravity / Gemini). Signed-off-by: Will Manning --- Cargo.lock | 4 +- encodings/elias-fano/Cargo.toml | 3 +- encodings/elias-fano/src/elias_fano/tests.rs | 74 ++++++ encodings/elias-fano/src/unary/tests.rs | 50 ++++ encodings/onpair/Cargo.toml | 3 +- encodings/onpair/src/compute/like.rs | 184 ++++++++++++++ encodings/onpair/src/tests.rs | 247 +++++++++++++++++++ encodings/onpair/tests/big_data.rs | 126 ---------- encodings/zigzag/Cargo.toml | 4 +- encodings/zigzag/src/compress.rs | 108 ++++++++ 10 files changed, 672 insertions(+), 131 deletions(-) delete mode 100644 encodings/onpair/tests/big_data.rs diff --git a/Cargo.lock b/Cargo.lock index 042d61b6722..ab6b3b269d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11684,6 +11684,7 @@ name = "vortex-elias-fano" version = "0.1.0" dependencies = [ "codspeed-divan-compat", + "hegeltest", "mimalloc", "num-traits", "prost 0.14.4", @@ -12134,6 +12135,7 @@ name = "vortex-onpair" version = "0.1.0" dependencies = [ "codspeed-divan-compat", + "hegeltest", "mimalloc", "num-traits", "onpair", @@ -12545,7 +12547,7 @@ dependencies = [ name = "vortex-zigzag" version = "0.1.0" dependencies = [ - "num-traits", + "hegeltest", "rstest", "vortex-array", "vortex-buffer", diff --git a/encodings/elias-fano/Cargo.toml b/encodings/elias-fano/Cargo.toml index a61bcfa605e..4d9175d7393 100644 --- a/encodings/elias-fano/Cargo.toml +++ b/encodings/elias-fano/Cargo.toml @@ -22,10 +22,11 @@ vortex-session = { workspace = true } [dev-dependencies] divan = { workspace = true } +hegeltest = { workspace = true } mimalloc = { workspace = true } rand = { workspace = true } rstest = { workspace = true } -vortex-array = { workspace = true, features = ["_test-harness"] } +vortex-array = { workspace = true, features = ["_test-harness-hegel"] } [[bench]] name = "unary" diff --git a/encodings/elias-fano/src/elias_fano/tests.rs b/encodings/elias-fano/src/elias_fano/tests.rs index 1ee9d886e6e..13549c3448f 100644 --- a/encodings/elias-fano/src/elias_fano/tests.rs +++ b/encodings/elias-fano/src/elias_fano/tests.rs @@ -1,6 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright the Vortex contributors +use hegel::TestCase; +use hegel::generators as gs; use prost::Message; use rstest::rstest; use vortex_array::Array; @@ -16,6 +18,8 @@ use vortex_array::arrays::PrimitiveArray; use vortex_array::assert_arrays_eq; use vortex_array::buffer::BufferHandle; use vortex_array::compute::conformance::consistency::test_array_consistency; +use vortex_array::compute::conformance::hegel::EncodingCheckOptions; +use vortex_array::compute::conformance::hegel::check_encoding_roundtrip_and_ops; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability::NonNullable; use vortex_array::dtype::PType; @@ -23,6 +27,7 @@ use vortex_array::test_harness::check_metadata; use vortex_array::validity::Validity; use vortex_array::vtable::VTable; use vortex_buffer::buffer; +use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_error::vortex_err; @@ -296,3 +301,72 @@ fn test_elias_fano_metadata() { .encode_to_vec(), ); } + +#[hegel::test(test_cases = 48, print_blob = true)] +fn test_elias_fano_hegel_encoding_harness(tc: TestCase) { + const UNSIGNED_PTYPES: [PType; 4] = [PType::U8, PType::U16, PType::U32, PType::U64]; + + let mut ctx = SESSION.create_execution_ctx(); + let ptype = tc.draw(gs::sampled_from(&UNSIGNED_PTYPES)); + let max_val: u64 = match ptype { + PType::U8 => u64::from(u8::MAX), + PType::U16 => u64::from(u16::MAX), + PType::U32 => u64::from(u32::MAX), + PType::U64 => u64::MAX, + _ => unreachable!(), + }; + let len = tc.draw(gs::integers::().max_value(96)); + let mut values: Vec = match tc.draw(gs::integers::().max_value(3)) { + 0 => vec![0; len], + 1 => (0..len) + .map(|_| tc.draw(gs::integers::().max_value(max_val.min(64)))) + .collect(), + 2 => (0..len) + .map(|_| match tc.draw(gs::integers::().max_value(5)) { + 0 => 0, + 1 => max_val, + _ => tc.draw(gs::integers::().max_value(max_val)), + }) + .collect(), + _ => (0..len) + .map(|_| tc.draw(gs::integers::().max_value(max_val.min(10_000)))) + .collect(), + }; + values.sort_unstable(); + + let canonical_prim = primitive(ptype, &values); + let ef = encode(&canonical_prim).vortex_expect("sorted unsigned encodes"); + + // Exercise both Primitive and Unary `upper` representations. + let encoded = if tc.draw(gs::booleans()) { + let counts = ef + .upper() + .clone() + .execute::(&mut ctx) + .vortex_expect("execute upper"); + if let Some(unary_upper) = unary_encode(counts.as_ref().as_::(), &mut ctx) + .vortex_expect("unary_encode upper") + { + EliasFano::try_new( + unary_upper.into_array(), + ef.lower().clone(), + ef.lower_bits(), + ) + .vortex_expect("ef with unary upper") + .into_array() + } else { + ef.into_array() + } + } else { + ef.into_array() + }; + + check_encoding_roundtrip_and_ops( + &tc, + &encoded, + &canonical_prim.into_array(), + &EncodingCheckOptions::default(), + &mut ctx, + ) + .vortex_expect("EliasFano harness check"); +} diff --git a/encodings/elias-fano/src/unary/tests.rs b/encodings/elias-fano/src/unary/tests.rs index 991cdb2c275..18ad246bb21 100644 --- a/encodings/elias-fano/src/unary/tests.rs +++ b/encodings/elias-fano/src/unary/tests.rs @@ -6,6 +6,8 @@ use std::hash::Hasher; use std::iter; use std::slice; +use hegel::TestCase; +use hegel::generators as gs; use prost::Message; use rand::RngExt; use rand::SeedableRng; @@ -27,6 +29,8 @@ use vortex_array::arrays::PrimitiveArray; use vortex_array::assert_arrays_eq; use vortex_array::buffer::BufferHandle; use vortex_array::compute::conformance::consistency::test_array_consistency; +use vortex_array::compute::conformance::hegel::EncodingCheckOptions; +use vortex_array::compute::conformance::hegel::check_encoding_roundtrip_and_ops; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability::NonNullable; use vortex_array::dtype::PType; @@ -39,6 +43,7 @@ use vortex_array::vtable::VTable; use vortex_buffer::BitBuffer; use vortex_buffer::ByteBuffer; use vortex_buffer::buffer; +use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_error::vortex_err; @@ -422,3 +427,48 @@ fn test_lazy_slice() -> VortexResult<()> { assert_arrays_eq!(sliced, expected, &mut SESSION.create_execution_ctx()); check_access(&sliced, &expected, 0x51CE) } + +#[hegel::test(test_cases = 48, print_blob = true)] +fn test_unary_hegel_encoding_harness(tc: TestCase) { + const UNSIGNED_PTYPES: [PType; 4] = [PType::U8, PType::U16, PType::U32, PType::U64]; + + let mut ctx = SESSION.create_execution_ctx(); + let ptype = tc.draw(gs::sampled_from(&UNSIGNED_PTYPES)); + let len = tc.draw(gs::integers::().max_value(96)); + let cap = u64::try_from((ptype.bit_width() - 1).min(24)).vortex_expect("fits u64"); + let values: Vec = match tc.draw(gs::integers::().max_value(2)) { + 0 => vec![0; len], + 1 => (0..len) + .map(|_| tc.draw(gs::integers::().max_value(cap.min(3)))) + .collect(), + _ => (0..len) + .map(|_| tc.draw(gs::integers::().max_value(cap))) + .collect(), + }; + let canonical_prim = primitive(ptype, &values); + let unary = unary_encode(canonical_prim.as_ref().as_::(), &mut ctx) + .vortex_expect("unary_encode") + .vortex_expect("bounded values must unary-encode"); + + // Half the time shift the bit buffer by a non-zero bit offset so sliced-bit paths run too. + let encoded = if tc.draw(gs::booleans()) { + let bit_offset = tc.draw(gs::integers::().min_value(1).max_value(15)); + let shifted: BitBuffer = iter::repeat_n(false, bit_offset) + .chain(unary.to_bit_buffer().iter()) + .collect(); + Unary::try_new(shifted.slice(bit_offset..), ptype, len) + .vortex_expect("shifted unary") + .into_array() + } else { + unary.into_array() + }; + + check_encoding_roundtrip_and_ops( + &tc, + &encoded, + &canonical_prim.into_array(), + &EncodingCheckOptions::default(), + &mut ctx, + ) + .vortex_expect("Unary harness check"); +} diff --git a/encodings/onpair/Cargo.toml b/encodings/onpair/Cargo.toml index b8f95012efb..d52904de126 100644 --- a/encodings/onpair/Cargo.toml +++ b/encodings/onpair/Cargo.toml @@ -30,9 +30,10 @@ _test-harness = ["vortex-array/_test-harness"] [dev-dependencies] divan = { workspace = true } +hegeltest = { workspace = true } mimalloc = { workspace = true } rstest = { workspace = true } -vortex-array = { workspace = true, features = ["_test-harness"] } +vortex-array = { workspace = true, features = ["_test-harness-hegel"] } [[bench]] name = "decode" diff --git a/encodings/onpair/src/compute/like.rs b/encodings/onpair/src/compute/like.rs index 9fbc3073eaf..a4eeab9fc44 100644 --- a/encodings/onpair/src/compute/like.rs +++ b/encodings/onpair/src/compute/like.rs @@ -120,16 +120,22 @@ impl Pattern { mod tests { use std::sync::LazyLock; + use hegel::TestCase; + use hegel::generators as gs; use rstest::rstest; use vortex_array::ArrayRef; use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::ConstantArray; use vortex_array::arrays::VarBinArray; + use vortex_array::arrays::VarBinViewArray; use vortex_array::assert_arrays_eq; + use vortex_array::compute::conformance::hegel::draw_validity_for; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; use vortex_array::optimizer::ArrayOptimizer; + use vortex_array::scalar::Scalar; + use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_error::vortex_err; use vortex_functions::like::Like; @@ -145,6 +151,8 @@ mod tests { static SESSION: LazyLock = LazyLock::new(|| { let session = VortexSession::empty(); + vortex_array::initialize(&session); + vortex_functions::initialize(&session); crate::initialize(&session); session }); @@ -286,4 +294,180 @@ mod tests { fn parse_pattern(#[case] pattern: &str, #[case] expected: Option) { assert_eq!(Pattern::parse(pattern.as_bytes()), expected); } + + fn escape_like_literal(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + for ch in s.chars() { + if matches!(ch, '%' | '_' | '\\') { + out.push('\\'); + } + out.push(ch); + } + out + } + + /// Differential property test for OnPair `Like` pushdown covering escaped `\%`/`\_`/`\\`, + /// cross-symbol substring boundaries, 254-byte DFA state boundaries, sliced/nullable inputs, + /// and negated/case-insensitive options against canonical `Utf8` `Like`. + #[hegel::test(test_cases = 48, print_blob = true)] + #[cfg_attr(miri, ignore)] + fn test_onpair_like_hegel_differential(tc: TestCase) { + const PIECES: [&str; 9] = [ + "", + "https://example.com/", + "a%b_c\\d", + "users/42/profile", + "%%", + "__", + "\\\\", + "utf8_你好_", + "0123456789abcdef0123456789abcdef", + ]; + + let mut ctx = SESSION.create_execution_ctx(); + let len = tc.draw(gs::integers::().min_value(1).max_value(48)); + let nullability = if tc.draw(gs::booleans()) { + Nullability::Nullable + } else { + Nullability::NonNullable + }; + let validity = draw_validity_for(&tc, nullability, len); + let mask = validity + .execute_mask(len, &mut ctx) + .vortex_expect("validity mask"); + + let include_long = tc.draw(gs::integers::().max_value(3)) == 0; + let long_base = "ab%cd_ef\\gh".repeat(26); // 286 bytes (> 254-byte DFA boundary) + let rows: Vec = (0..len) + .map(|i| { + if include_long && i == len / 2 { + format!("prefix_{long_base}_suffix") + } else { + let parts = tc.draw(gs::integers::().min_value(1).max_value(4)); + (0..parts) + .map(|_| tc.draw(gs::sampled_from(&PIECES))) + .collect() + } + }) + .collect(); + + let canonical_raw = VarBinViewArray::from_iter( + rows.iter() + .enumerate() + .map(|(i, s)| mask.value(i).then_some(s.as_str())), + DType::Utf8(nullability), + ) + .into_array(); + let encoded_raw = onpair_compress(&canonical_raw, DEFAULT_CONFIG, &mut ctx) + .vortex_expect("onpair_compress"); + + let (encoded, canonical) = if len > 1 && tc.draw(gs::booleans()) { + let a = tc.draw(gs::integers::().max_value(len)); + let b = tc.draw(gs::integers::().max_value(len)); + let range = a.min(b)..a.max(b); + ( + encoded_raw + .slice(range.clone()) + .vortex_expect("slice onpair") + .optimize_ctx(&SESSION) + .vortex_expect("optimize slice"), + canonical_raw.slice(range).vortex_expect("slice canonical"), + ) + } else { + (encoded_raw, canonical_raw) + }; + + // Pick a literal slice from an actual row (crossing token boundaries), an escaped + // metacharacter sequence, or a ~254-byte boundary substring. + let sample_row = &rows[tc.draw(gs::integers::().max_value(len - 1))]; + let pattern_str = match tc.draw(gs::integers::().max_value(6)) { + 0 => "%".to_owned(), + 1 => { + // Substring crossing arbitrary char boundaries of a corpus row. + let chars: Vec = sample_row.chars().collect(); + let sub: String = if chars.is_empty() { + String::new() + } else { + let start = tc.draw(gs::integers::().max_value(chars.len())); + let end = tc.draw( + gs::integers::() + .min_value(start) + .max_value(chars.len()), + ); + chars[start..end].iter().collect() + }; + let escaped = escape_like_literal(&sub); + match tc.draw(gs::integers::().max_value(3)) { + 0 => escaped, + 1 => format!("{escaped}%"), + 2 => format!("%{escaped}%"), + _ => format!("%{escaped}"), + } + } + 2 => { + // Around the 254-byte ContainsScan state limit (250..=260 bytes). + let target_len = tc.draw(gs::integers::().min_value(250).max_value(260)); + let sub = &long_base[..target_len.min(long_base.len())]; + format!("%{}%", escape_like_literal(sub)) + } + 3 => { + // Explicit escaped metacharacters + trailing backslash edge cases. + tc.draw(gs::sampled_from(&[ + "%\\%_%", + "%\\_%", + "%\\\\%", + "a\\%b\\_c\\\\d%", + "%a\\", + "a\\", + ])) + .to_owned() + } + 4 => format!( + "{}%{}", + escape_like_literal("https"), + escape_like_literal("profile") + ), + 5 => "a_b%".to_owned(), + _ => escape_like_literal(sample_row), + }; + + let pat_nullability = if tc.draw(gs::booleans()) { + Nullability::Nullable + } else { + Nullability::NonNullable + }; + let pat_scalar = if pat_nullability == Nullability::Nullable + && tc.draw(gs::integers::().max_value(5)) == 0 + { + Scalar::null(DType::Utf8(Nullability::Nullable)) + } else { + Scalar::utf8(pattern_str, pat_nullability) + }; + let pat_arr = ConstantArray::new(pat_scalar, encoded.len()).into_array(); + let options = LikeOptions { + negated: tc.draw(gs::booleans()), + case_insensitive: tc.draw(gs::booleans()), + }; + + let expected = Like::try_new(canonical, pat_arr.clone(), options) + .vortex_expect("canonical like") + .into_array(); + let actual = Like::try_new(encoded.clone(), pat_arr.clone(), options) + .vortex_expect("onpair like") + .into_array(); + assert_arrays_eq!(&actual, &expected, &mut ctx); + assert_arrays_eq!( + actual.optimize_ctx(&SESSION).vortex_expect("optimize like"), + &expected, + &mut ctx + ); + + if let Some(onpair_view) = encoded.as_opt::() + && let Some(kernel_out) = + ::like(onpair_view, &pat_arr, options, &mut ctx) + .vortex_expect("like kernel") + { + assert_arrays_eq!(kernel_out, expected, &mut ctx); + } + } } diff --git a/encodings/onpair/src/tests.rs b/encodings/onpair/src/tests.rs index ef9bc48aa88..f2695c08324 100644 --- a/encodings/onpair/src/tests.rs +++ b/encodings/onpair/src/tests.rs @@ -3,6 +3,8 @@ use std::sync::LazyLock; +use hegel::TestCase; +use hegel::generators as gs; use onpair::CompactDictionaryView; use prost::Message; use rstest::rstest; @@ -23,6 +25,9 @@ use vortex_array::builders::VarBinBuilder; use vortex_array::builtins::ArrayBuiltins; use vortex_array::compute::conformance::consistency::test_array_consistency; use vortex_array::compute::conformance::filter::test_filter_conformance; +use vortex_array::compute::conformance::hegel::EncodingCheckOptions; +use vortex_array::compute::conformance::hegel::check_encoding_roundtrip_and_ops; +use vortex_array::compute::conformance::hegel::draw_validity_for; use vortex_array::compute::conformance::take::test_take_conformance; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; @@ -33,7 +38,9 @@ use vortex_array::scalar_fn::builtin::operators::CompareMode; use vortex_array::scalar_fn::builtin::operators::CompareOperator; use vortex_array::test_harness::check_metadata; use vortex_array::validity::Validity; +use vortex_buffer::Buffer; use vortex_buffer::BufferMut; +use vortex_error::VortexExpect; use vortex_session::VortexSession; use crate::DEFAULT_CONFIG; @@ -45,6 +52,7 @@ use crate::compress::onpair_compress; static SESSION: LazyLock = LazyLock::new(|| { let session = VortexSession::empty(); + vortex_array::initialize(&session); crate::initialize(&session); session }); @@ -867,3 +875,242 @@ fn codes_buffer_has_little_spare_capacity( ); Ok(()) } + +fn draw_onpair_strings(tc: &TestCase, len: usize) -> Vec { + const PREFIXES: [&str; 6] = [ + "", + "https://www.example.com/", + "GET /api/v1/users/", + "redis://cache-", + "utf8_你好_", + "a/b/c/", + ]; + const SUFFIXES: [&str; 6] = [ + "", + "profile HTTP/1.1", + "products/42", + ".svc.cluster.local:6379", + "long_non_inlined_payload_segment_value", + "x", + ]; + (0..len) + .map(|_| match tc.draw(gs::integers::().max_value(3)) { + 0 => String::new(), + 1 | 2 => format!( + "{}{:04x}/{}", + tc.draw(gs::sampled_from(&PREFIXES)), + tc.draw(gs::integers::().max_value(31)), + tc.draw(gs::sampled_from(&SUFFIXES)), + ), + _ => tc.draw(gs::sampled_from(&SUFFIXES)).to_owned(), + }) + .collect() +} + +/// End-to-end smoke check on a realistic URL/log corpus covering multi-byte merged dictionary +/// tokens, canonical decode, and equality pushdown (replaces the old 100k-row `big_data` bench). +#[test] +#[cfg_attr(miri, ignore)] +fn test_onpair_realistic_corpus_roundtrip_and_eq() -> vortex_error::VortexResult<()> { + const TEMPLATES: [&str; 6] = [ + "GET /api/v1/users/{id}/profile HTTP/1.1", + "POST /api/v1/users/{id}/sessions HTTP/1.1", + "https://www.example.com/products/{id}", + "https://cdn.example.com/img/{id}.webp", + "redis://cache-{id}.svc.cluster.local:6379", + "ERROR request_id={id} method=PUT status=500", + ]; + let len = 2_048; + let strings: Vec = (0..len) + .map(|idx| TEMPLATES[idx % TEMPLATES.len()].replace("{id}", &format!("{:04x}", idx % 256))) + .collect(); + let varbin = VarBinArray::from_iter( + strings.iter().map(|s| Some(s.as_bytes())), + DType::Utf8(Nullability::NonNullable), + ); + let mut ctx = SESSION.create_execution_ctx(); + let encoded = onpair_compress(&varbin.clone().into_array(), DEFAULT_CONFIG, &mut ctx)?; + assert_arrays_eq!(&encoded, &varbin, &mut ctx); + + let needle = strings[42].as_str(); + let eq = encoded.compare( + ConstantArray::new(needle, len).into_array(), + CompareOperator::Eq, + CompareMode::TOTAL_ORDER, + )?; + assert_arrays_eq!( + eq, + BoolArray::from_iter(strings.iter().map(|s| s == needle)), + &mut ctx + ); + Ok(()) +} + +#[hegel::test(test_cases = 40, print_blob = true)] +#[cfg_attr(miri, ignore)] +fn test_onpair_hegel_encoding_harness(tc: TestCase) { + let mut ctx = SESSION.create_execution_ctx(); + let len = if tc.draw(gs::integers::().max_value(4)) == 0 { + tc.draw(gs::integers::().min_value(65).max_value(140)) + } else { + tc.draw(gs::integers::().max_value(64)) + }; + let nullability = if tc.draw(gs::booleans()) { + Nullability::Nullable + } else { + Nullability::NonNullable + }; + let is_binary = tc.draw(gs::booleans()); + let dtype = if is_binary { + DType::Binary(nullability) + } else { + DType::Utf8(nullability) + }; + let validity = draw_validity_for(&tc, nullability, len); + let mask = validity + .execute_mask(len, &mut ctx) + .vortex_expect("validity mask"); + let strings = draw_onpair_strings(&tc, len); + let canonical = VarBinViewArray::from_iter( + strings + .iter() + .enumerate() + .map(|(i, s)| mask.value(i).then_some(s.as_bytes())), + dtype, + ) + .into_array(); + let encoded = + onpair_compress(&canonical, DEFAULT_CONFIG, &mut ctx).vortex_expect("onpair_compress"); + + check_encoding_roundtrip_and_ops( + &tc, + &encoded, + &canonical, + &EncodingCheckOptions::default(), + &mut ctx, + ) + .vortex_expect("OnPair harness check"); +} + +/// Dense repeated `Dict(codes, OnPair)` takes across nullable/sliced/repeated codes (#10422). +#[hegel::test(test_cases = 40, print_blob = true)] +#[cfg_attr(miri, ignore)] +fn test_onpair_dict_dense_repeated_takes(tc: TestCase) { + let mut ctx = SESSION.create_execution_ctx(); + let raw_len = tc.draw(gs::integers::().min_value(1).max_value(48)); + let val_nullability = if tc.draw(gs::booleans()) { + Nullability::Nullable + } else { + Nullability::NonNullable + }; + let val_validity = draw_validity_for(&tc, val_nullability, raw_len); + let val_mask = val_validity + .execute_mask(raw_len, &mut ctx) + .vortex_expect("values mask"); + let strings = draw_onpair_strings(&tc, raw_len); + let canonical_raw = VarBinViewArray::from_iter( + strings + .iter() + .enumerate() + .map(|(i, s)| val_mask.value(i).then_some(s.as_bytes())), + DType::Utf8(val_nullability), + ) + .into_array(); + let encoded_raw = + onpair_compress(&canonical_raw, DEFAULT_CONFIG, &mut ctx).vortex_expect("onpair_compress"); + + let (encoded_vals, canonical_vals) = if raw_len > 1 && tc.draw(gs::booleans()) { + let start = tc.draw(gs::integers::().max_value(raw_len - 1)); + let end = tc.draw( + gs::integers::() + .min_value(start + 1) + .max_value(raw_len), + ); + ( + encoded_raw + .slice(start..end) + .vortex_expect("slice onpair") + .optimize_ctx(&SESSION) + .vortex_expect("optimize slice"), + canonical_raw + .slice(start..end) + .vortex_expect("slice canonical"), + ) + } else { + (encoded_raw, canonical_raw) + }; + + let vals_len = canonical_vals.len(); + // Draw more codes than distinct values so take paths exercise heavy code repetition. + let codes_len = tc.draw(gs::integers::().max_value(160)); + let raw_codes: Vec = if codes_len == 0 { + Vec::new() + } else { + let max_code = u16::try_from(vals_len - 1).vortex_expect("fits u16"); + tc.draw( + gs::vecs(gs::integers::().max_value(max_code)) + .min_size(codes_len) + .max_size(codes_len), + ) + }; + let codes_nullability = if tc.draw(gs::booleans()) { + Nullability::Nullable + } else { + Nullability::NonNullable + }; + let codes_validity = draw_validity_for(&tc, codes_nullability, codes_len); + let codes = match tc.draw(gs::integers::().max_value(3)) { + 0 => PrimitiveArray::new( + Buffer::from_iter( + raw_codes + .iter() + .map(|&c| u8::try_from(c).vortex_expect("u8")), + ), + codes_validity, + ) + .into_array(), + 1 => PrimitiveArray::new(Buffer::from(raw_codes), codes_validity).into_array(), + 2 => PrimitiveArray::new( + Buffer::from_iter(raw_codes.iter().map(|&c| u32::from(c))), + codes_validity, + ) + .into_array(), + _ => PrimitiveArray::new( + Buffer::from_iter(raw_codes.iter().map(|&c| u64::from(c))), + codes_validity, + ) + .into_array(), + }; + + let dict = DictArray::try_new(codes.clone(), encoded_vals) + .vortex_expect("dict onpair") + .into_array(); + let expected = canonical_vals.take(codes).vortex_expect("canonical take"); + + let (dict, expected) = if codes_len > 0 && tc.draw(gs::booleans()) { + let a = tc.draw(gs::integers::().max_value(codes_len)); + let b = tc.draw(gs::integers::().max_value(codes_len)); + let range = a.min(b)..a.max(b); + ( + dict.slice(range.clone()).vortex_expect("slice dict"), + expected.slice(range).vortex_expect("slice expected"), + ) + } else { + (dict, expected) + }; + + assert_arrays_eq!(&dict, &expected, &mut ctx); + let optimized = dict.optimize_ctx(&SESSION).vortex_expect("optimize dict"); + assert_arrays_eq!(&optimized, &expected, &mut ctx); + if !optimized.is_empty() { + let probe = tc.draw(gs::integers::().max_value(optimized.len() - 1)); + assert_eq!( + optimized + .execute_scalar(probe, &mut ctx) + .vortex_expect("probe dict"), + expected + .execute_scalar(probe, &mut ctx) + .vortex_expect("probe expected"), + ); + } +} diff --git a/encodings/onpair/tests/big_data.rs b/encodings/onpair/tests/big_data.rs deleted file mode 100644 index 42b24367a66..00000000000 --- a/encodings/onpair/tests/big_data.rs +++ /dev/null @@ -1,126 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: Copyright the Vortex contributors -// -//! End-to-end smoke test on a realistically-sized input. Validates the -//! pure-Rust decode path and pushdown predicates end-to-end through the new -//! u16-codes layout. - -#![allow( - clippy::cast_possible_truncation, - clippy::redundant_clone, - clippy::tests_outside_test_module, - clippy::use_debug -)] - -use std::sync::LazyLock; -use std::time::Instant; - -use vortex_array::IntoArray; -use vortex_array::VortexSessionExecute; -use vortex_array::aggregate_fn::fns::sum::sum; -use vortex_array::arrays::BoolArray; -use vortex_array::arrays::ConstantArray; -use vortex_array::arrays::VarBinArray; -use vortex_array::arrays::VarBinViewArray; -use vortex_array::assert_arrays_eq; -use vortex_array::builtins::ArrayBuiltins; -use vortex_array::dtype::DType; -use vortex_array::dtype::Nullability; -use vortex_array::scalar_fn::builtin::operators::CompareMode; -use vortex_array::scalar_fn::builtin::operators::CompareOperator; -use vortex_onpair::DEFAULT_CONFIG; -use vortex_onpair::onpair_compress; -use vortex_session::VortexSession; - -static SESSION: LazyLock = LazyLock::new(|| { - let session = VortexSession::empty(); - vortex_onpair::initialize(&session); - session -}); - -fn corpus(n: usize) -> Vec { - let templates: &[&str] = &[ - "GET /api/v1/users/{id}/profile HTTP/1.1", - "POST /api/v1/users/{id}/sessions HTTP/1.1", - "GET /static/js/app.{id}.js HTTP/1.1", - "GET /static/css/app.{id}.css HTTP/1.1", - "https://www.example.com/products/{id}", - "https://cdn.example.com/img/{id}.webp", - "https://api.example.com/v2/orders/{id}", - "ftp://files.example.com/dump/{id}.tar.gz", - "ssh://deploy@build-{id}.internal:22", - "redis://cache-{id}.svc.cluster.local:6379", - "INFO request_id={id} method=GET status=200", - "WARN request_id={id} method=POST status=429", - "ERROR request_id={id} method=PUT status=500", - ]; - let mut out = Vec::with_capacity(n); - let mut state = 0x9e37_79b9_7f4a_7c15_u64; - for _ in 0..n { - state = state - .wrapping_mul(6364136223846793005) - .wrapping_add(1442695040888963407); - let pick = (state as usize) % templates.len(); - let id = state as u32; - out.push(templates[pick].replace("{id}", &format!("{:08x}", id))); - } - out -} - -#[test] -#[cfg_attr(miri, ignore)] -fn smoke_100k_rows() -> vortex_error::VortexResult<()> { - let n = 100_000; - let strings = corpus(n); - let raw_bytes: usize = strings.iter().map(|s| s.len()).sum(); - - let varbin = VarBinArray::from_iter( - strings.iter().map(|s| Some(s.as_bytes())), - DType::Utf8(Nullability::NonNullable), - ); - - let mut ctx = SESSION.create_execution_ctx(); - let t0 = Instant::now(); - let arr = onpair_compress(&varbin.into_array(), DEFAULT_CONFIG, &mut ctx)?; - let compress_elapsed = t0.elapsed(); - eprintln!( - "compressed {} rows ({} raw bytes) in {:?}", - n, raw_bytes, compress_elapsed - ); - - let arr_ref = arr.into_array(); - - // Full canonical round-trip via the pure-Rust decoder. - let t0 = Instant::now(); - let decoded = arr_ref.clone().execute::(&mut ctx)?; - eprintln!("canonicalized in {:?}", t0.elapsed()); - - assert_eq!(decoded.len(), n); - let mask = decoded.validity()?.execute_mask(decoded.len(), &mut ctx)?; - for i in 0..decoded.len() { - let got = mask.value(i).then(|| decoded.bytes_at(i)); - let want = strings[i].as_bytes(); - assert_eq!(got.as_deref(), Some(want), "row {} mismatch", i); - } - eprintln!("roundtrip OK on all {} rows", n); - - // Equality pushdown: pick a specific row's value and ensure the kernel - // finds all occurrences. - let needle_row = 42; - let needle = strings[needle_row].clone(); - let want_eq = strings.iter().filter(|s| **s == needle).count(); - let eq = arr_ref.compare( - ConstantArray::new(needle.as_str(), n).into_array(), - CompareOperator::Eq, - CompareMode::TOTAL_ORDER, - )?; - let eq_count = sum(&eq, &mut ctx)?.as_primitive().as_::().unwrap(); - assert_eq!(eq_count, want_eq); - assert_arrays_eq!( - eq, - BoolArray::from_iter(strings.iter().map(|s| *s == needle)), - &mut ctx - ); - eprintln!("eq pushdown matches reference count ({})", want_eq); - Ok(()) -} diff --git a/encodings/zigzag/Cargo.toml b/encodings/zigzag/Cargo.toml index ee12cab3537..6ac1546bee3 100644 --- a/encodings/zigzag/Cargo.toml +++ b/encodings/zigzag/Cargo.toml @@ -13,7 +13,6 @@ rust-version = { workspace = true } version = { workspace = true } [dependencies] -num-traits = { workspace = true } vortex-array = { workspace = true } vortex-buffer = { workspace = true } vortex-compute = { workspace = true } @@ -23,8 +22,9 @@ vortex-session = { workspace = true } zigzag = { workspace = true } [dev-dependencies] +hegeltest = { workspace = true } rstest = { workspace = true } -vortex-array = { workspace = true, features = ["_test-harness"] } +vortex-array = { workspace = true, features = ["_test-harness-hegel"] } [lints] workspace = true diff --git a/encodings/zigzag/src/compress.rs b/encodings/zigzag/src/compress.rs index 521d5281502..4c08c1bd368 100644 --- a/encodings/zigzag/src/compress.rs +++ b/encodings/zigzag/src/compress.rs @@ -104,10 +104,18 @@ where mod tests { use std::sync::LazyLock; + use hegel::TestCase; + use hegel::generators as gs; use rstest::rstest; use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::assert_arrays_eq; + use vortex_array::compute::conformance::hegel::EncodingCheckOptions; + use vortex_array::compute::conformance::hegel::check_encoding_roundtrip_and_ops; + use vortex_array::compute::conformance::hegel::draw_validity_for; + use vortex_array::dtype::Nullability; + use vortex_array::optimizer::ArrayOptimizer; + use vortex_buffer::Buffer; use vortex_session::VortexSession; use super::*; @@ -115,6 +123,7 @@ mod tests { static SESSION: LazyLock = LazyLock::new(|| { let session = VortexSession::empty(); + vortex_array::initialize(&session); crate::initialize(&session); session }); @@ -191,4 +200,103 @@ mod tests { assert_arrays_eq!(decoded, expected, &mut ctx); Ok(()) } + + fn draw_signed_prim( + tc: &TestCase, + len: usize, + validity: Validity, + boundaries: &[T], + ) -> PrimitiveArray + where + T: NativePType + gs::Integer, + { + let vals: Vec = (0..len) + .map(|_| { + if tc.draw(gs::integers::().max_value(3)) == 0 { + tc.draw(gs::sampled_from(boundaries)) + } else { + tc.draw(gs::integers::()) + } + }) + .collect(); + PrimitiveArray::new(Buffer::from(vals), validity) + } + + #[hegel::test(test_cases = 48, print_blob = true)] + fn test_zigzag_hegel_encoding_harness(tc: TestCase) { + let mut ctx = SESSION.create_execution_ctx(); + let len = if tc.draw(gs::integers::().max_value(4)) == 0 { + tc.draw(gs::integers::().min_value(65).max_value(140)) + } else { + tc.draw(gs::integers::().max_value(64)) + }; + let nullability = if tc.draw(gs::booleans()) { + Nullability::Nullable + } else { + Nullability::NonNullable + }; + let validity = draw_validity_for(&tc, nullability, len); + let prim = match tc.draw(gs::integers::().max_value(3)) { + 0 => draw_signed_prim::( + &tc, + len, + validity, + &[i8::MIN, i8::MIN + 1, -1, 0, 1, i8::MAX], + ), + 1 => draw_signed_prim::( + &tc, + len, + validity, + &[i16::MIN, i16::MIN + 1, -1, 0, 1, i16::MAX], + ), + 2 => draw_signed_prim::( + &tc, + len, + validity, + &[i32::MIN, i32::MIN + 1, -1, 0, 1, i32::MAX], + ), + _ => draw_signed_prim::( + &tc, + len, + validity, + &[i64::MIN, i64::MIN + 1, -1, 0, 1, i64::MAX], + ), + }; + + // Exercise owned in-place decode (#12048) on a uniquely owned encoded buffer. + let owned_encoded = zigzag_encode(prim.as_view()) + .vortex_expect("zigzag_encode") + .into_array(); + assert_arrays_eq!(owned_encoded, &prim, &mut ctx); + + // Exercise shared Arc out-of-place decode, slicing, serde, compare, and chained ops. + let encoded = zigzag_encode(prim.as_view()) + .vortex_expect("zigzag_encode") + .into_array(); + let canonical = prim.into_array(); + let (encoded, canonical) = if len > 0 && tc.draw(gs::booleans()) { + let a = tc.draw(gs::integers::().max_value(len)); + let b = tc.draw(gs::integers::().max_value(len)); + let range = a.min(b)..a.max(b); + ( + encoded + .slice(range.clone()) + .vortex_expect("slice zigzag") + .optimize_ctx(&SESSION) + .vortex_expect("optimize sliced zigzag"), + canonical.slice(range).vortex_expect("slice canonical"), + ) + } else { + (encoded, canonical) + }; + + check_encoding_roundtrip_and_ops( + &tc, + &encoded, + &canonical, + &EncodingCheckOptions::default(), + &mut ctx, + ) + .vortex_expect("ZigZag harness check"); + } } From fc5914583fbd9d86f9a3207064e4981a0f1d3e6d Mon Sep 17 00:00:00 2001 From: Will Manning Date: Sun, 29 Nov 2026 20:03:58 +0000 Subject: [PATCH 2/4] Address review feedback on ZigZag in-place decode and OnPair big_data test Decode owned_encoded by value before comparing in test_zigzag_hegel_encoding_harness so the uniquely owned in-place decode path is exercised. Restore the 100k-row OnPair big_data smoke test without Instant timing or eprintln output and remove the redundant smaller corpus test. Signed-off-by: Will Manning Co-Authored-By: Will Manning --- encodings/onpair/src/tests.rs | 39 ---------- encodings/onpair/tests/big_data.rs | 112 +++++++++++++++++++++++++++++ encodings/zigzag/src/compress.rs | 5 +- 3 files changed, 116 insertions(+), 40 deletions(-) create mode 100644 encodings/onpair/tests/big_data.rs diff --git a/encodings/onpair/src/tests.rs b/encodings/onpair/src/tests.rs index f2695c08324..df07c40a272 100644 --- a/encodings/onpair/src/tests.rs +++ b/encodings/onpair/src/tests.rs @@ -907,45 +907,6 @@ fn draw_onpair_strings(tc: &TestCase, len: usize) -> Vec { .collect() } -/// End-to-end smoke check on a realistic URL/log corpus covering multi-byte merged dictionary -/// tokens, canonical decode, and equality pushdown (replaces the old 100k-row `big_data` bench). -#[test] -#[cfg_attr(miri, ignore)] -fn test_onpair_realistic_corpus_roundtrip_and_eq() -> vortex_error::VortexResult<()> { - const TEMPLATES: [&str; 6] = [ - "GET /api/v1/users/{id}/profile HTTP/1.1", - "POST /api/v1/users/{id}/sessions HTTP/1.1", - "https://www.example.com/products/{id}", - "https://cdn.example.com/img/{id}.webp", - "redis://cache-{id}.svc.cluster.local:6379", - "ERROR request_id={id} method=PUT status=500", - ]; - let len = 2_048; - let strings: Vec = (0..len) - .map(|idx| TEMPLATES[idx % TEMPLATES.len()].replace("{id}", &format!("{:04x}", idx % 256))) - .collect(); - let varbin = VarBinArray::from_iter( - strings.iter().map(|s| Some(s.as_bytes())), - DType::Utf8(Nullability::NonNullable), - ); - let mut ctx = SESSION.create_execution_ctx(); - let encoded = onpair_compress(&varbin.clone().into_array(), DEFAULT_CONFIG, &mut ctx)?; - assert_arrays_eq!(&encoded, &varbin, &mut ctx); - - let needle = strings[42].as_str(); - let eq = encoded.compare( - ConstantArray::new(needle, len).into_array(), - CompareOperator::Eq, - CompareMode::TOTAL_ORDER, - )?; - assert_arrays_eq!( - eq, - BoolArray::from_iter(strings.iter().map(|s| s == needle)), - &mut ctx - ); - Ok(()) -} - #[hegel::test(test_cases = 40, print_blob = true)] #[cfg_attr(miri, ignore)] fn test_onpair_hegel_encoding_harness(tc: TestCase) { diff --git a/encodings/onpair/tests/big_data.rs b/encodings/onpair/tests/big_data.rs new file mode 100644 index 00000000000..637eb6dfad9 --- /dev/null +++ b/encodings/onpair/tests/big_data.rs @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright the Vortex contributors +// +//! End-to-end smoke test on a realistically-sized input. Validates the +//! pure-Rust decode path and pushdown predicates end-to-end through the new +//! u16-codes layout. + +#![allow( + clippy::cast_possible_truncation, + clippy::redundant_clone, + clippy::tests_outside_test_module, + clippy::use_debug +)] + +use std::sync::LazyLock; + +use vortex_array::IntoArray; +use vortex_array::VortexSessionExecute; +use vortex_array::aggregate_fn::fns::sum::sum; +use vortex_array::arrays::BoolArray; +use vortex_array::arrays::ConstantArray; +use vortex_array::arrays::VarBinArray; +use vortex_array::arrays::VarBinViewArray; +use vortex_array::assert_arrays_eq; +use vortex_array::builtins::ArrayBuiltins; +use vortex_array::dtype::DType; +use vortex_array::dtype::Nullability; +use vortex_array::scalar_fn::builtin::operators::CompareMode; +use vortex_array::scalar_fn::builtin::operators::CompareOperator; +use vortex_onpair::DEFAULT_CONFIG; +use vortex_onpair::onpair_compress; +use vortex_session::VortexSession; + +static SESSION: LazyLock = LazyLock::new(|| { + let session = VortexSession::empty(); + vortex_onpair::initialize(&session); + session +}); + +fn corpus(n: usize) -> Vec { + let templates: &[&str] = &[ + "GET /api/v1/users/{id}/profile HTTP/1.1", + "POST /api/v1/users/{id}/sessions HTTP/1.1", + "GET /static/js/app.{id}.js HTTP/1.1", + "GET /static/css/app.{id}.css HTTP/1.1", + "https://www.example.com/products/{id}", + "https://cdn.example.com/img/{id}.webp", + "https://api.example.com/v2/orders/{id}", + "ftp://files.example.com/dump/{id}.tar.gz", + "ssh://deploy@build-{id}.internal:22", + "redis://cache-{id}.svc.cluster.local:6379", + "INFO request_id={id} method=GET status=200", + "WARN request_id={id} method=POST status=429", + "ERROR request_id={id} method=PUT status=500", + ]; + let mut out = Vec::with_capacity(n); + let mut state = 0x9e37_79b9_7f4a_7c15_u64; + for _ in 0..n { + state = state + .wrapping_mul(6364136223846793005) + .wrapping_add(1442695040888963407); + let pick = (state as usize) % templates.len(); + let id = state as u32; + out.push(templates[pick].replace("{id}", &format!("{:08x}", id))); + } + out +} + +#[test] +#[cfg_attr(miri, ignore)] +fn smoke_100k_rows() -> vortex_error::VortexResult<()> { + let n = 100_000; + let strings = corpus(n); + + let varbin = VarBinArray::from_iter( + strings.iter().map(|s| Some(s.as_bytes())), + DType::Utf8(Nullability::NonNullable), + ); + + let mut ctx = SESSION.create_execution_ctx(); + let arr = onpair_compress(&varbin.into_array(), DEFAULT_CONFIG, &mut ctx)?; + let arr_ref = arr.into_array(); + + // Full canonical round-trip via the pure-Rust decoder. + let decoded = arr_ref.clone().execute::(&mut ctx)?; + assert_eq!(decoded.len(), n); + let mask = decoded.validity()?.execute_mask(decoded.len(), &mut ctx)?; + for i in 0..decoded.len() { + let got = mask.value(i).then(|| decoded.bytes_at(i)); + let want = strings[i].as_bytes(); + assert_eq!(got.as_deref(), Some(want), "row {} mismatch", i); + } + + // Equality pushdown: pick a specific row's value and ensure the kernel + // finds all occurrences. + let needle_row = 42; + let needle = strings[needle_row].clone(); + let want_eq = strings.iter().filter(|s| **s == needle).count(); + let eq = arr_ref.compare( + ConstantArray::new(needle.as_str(), n).into_array(), + CompareOperator::Eq, + CompareMode::TOTAL_ORDER, + )?; + let eq_count = sum(&eq, &mut ctx)?.as_primitive().as_::().unwrap(); + assert_eq!(eq_count, want_eq); + assert_arrays_eq!( + eq, + BoolArray::from_iter(strings.iter().map(|s| *s == needle)), + &mut ctx + ); + Ok(()) +} diff --git a/encodings/zigzag/src/compress.rs b/encodings/zigzag/src/compress.rs index 4c08c1bd368..6ac460030bf 100644 --- a/encodings/zigzag/src/compress.rs +++ b/encodings/zigzag/src/compress.rs @@ -267,7 +267,10 @@ mod tests { let owned_encoded = zigzag_encode(prim.as_view()) .vortex_expect("zigzag_encode") .into_array(); - assert_arrays_eq!(owned_encoded, &prim, &mut ctx); + let owned_decoded = owned_encoded + .execute::(&mut ctx) + .vortex_expect("owned zigzag decode"); + assert_arrays_eq!(owned_decoded, &prim, &mut ctx); // Exercise shared Arc out-of-place decode, slicing, serde, compare, and chained ops. let encoded = zigzag_encode(prim.as_view()) From ed4fe5f01dcbe947e4653ecd0e6c547e3d4594f3 Mon Sep 17 00:00:00 2001 From: Will Manning Date: Sun, 29 Nov 2026 20:10:39 +0000 Subject: [PATCH 3/4] Strengthen ZigZag in-place decode and OnPair take/like property assertions Assert buffer pointer reuse on owned ZigZag decode, exercise OnPair's >= 1024-row TakeExecute specialization in test_onpair_dict_dense_repeated_takes, and assert OnPair LikeKernel pushdown for supported patterns in test_onpair_like_hegel_differential. Signed-off-by: Will Manning Co-Authored-By: Will Manning --- encodings/onpair/src/compute/like.rs | 50 ++++++++++++++---- encodings/onpair/src/tests.rs | 78 ++++++++++++++++++++++------ encodings/zigzag/src/compress.rs | 18 +++++-- 3 files changed, 116 insertions(+), 30 deletions(-) diff --git a/encodings/onpair/src/compute/like.rs b/encodings/onpair/src/compute/like.rs index a4eeab9fc44..50b8c572500 100644 --- a/encodings/onpair/src/compute/like.rs +++ b/encodings/onpair/src/compute/like.rs @@ -380,7 +380,8 @@ mod tests { // Pick a literal slice from an actual row (crossing token boundaries), an escaped // metacharacter sequence, or a ~254-byte boundary substring. let sample_row = &rows[tc.draw(gs::integers::().max_value(len - 1))]; - let pattern_str = match tc.draw(gs::integers::().max_value(6)) { + let pattern_branch = tc.draw(gs::integers::().max_value(6)); + let pattern_str = match pattern_branch { 0 => "%".to_owned(), 1 => { // Substring crossing arbitrary char boundaries of a corpus row. @@ -436,12 +437,12 @@ mod tests { } else { Nullability::NonNullable }; - let pat_scalar = if pat_nullability == Nullability::Nullable - && tc.draw(gs::integers::().max_value(5)) == 0 - { + let is_null_pat = pat_nullability == Nullability::Nullable + && tc.draw(gs::integers::().max_value(5)) == 0; + let pat_scalar = if is_null_pat { Scalar::null(DType::Utf8(Nullability::Nullable)) } else { - Scalar::utf8(pattern_str, pat_nullability) + Scalar::utf8(pattern_str.clone(), pat_nullability) }; let pat_arr = ConstantArray::new(pat_scalar, encoded.len()).into_array(); let options = LikeOptions { @@ -462,12 +463,39 @@ mod tests { &mut ctx ); - if let Some(onpair_view) = encoded.as_opt::() - && let Some(kernel_out) = - ::like(onpair_view, &pat_arr, options, &mut ctx) - .vortex_expect("like kernel") - { - assert_arrays_eq!(kernel_out, expected, &mut ctx); + if let Some(onpair_view) = encoded.as_opt::() { + let kernel_out = ::like(onpair_view, &pat_arr, options, &mut ctx) + .vortex_expect("like kernel"); + if !options.case_insensitive && !is_null_pat { + match Pattern::parse(pattern_str.as_bytes()) { + Some(Pattern::Any | Pattern::Equals(_) | Pattern::StartsWith(_)) => { + let kernel_out = kernel_out + .vortex_expect("OnPair LikeKernel should push down parsed pattern"); + assert_arrays_eq!(kernel_out, &expected, &mut ctx); + } + Some(Pattern::Contains(lit)) + if pattern_branch == 2 + && include_long + && !lit.is_empty() + && lit.len() <= 254 => + { + let kernel_out = kernel_out.vortex_expect( + "OnPair LikeKernel should push down <= 254-byte ContainsScan", + ); + assert_arrays_eq!(kernel_out, &expected, &mut ctx); + } + Some(Pattern::Contains(_)) => { + if let Some(kernel_out) = kernel_out { + assert_arrays_eq!(kernel_out, &expected, &mut ctx); + } + } + None => { + assert!(kernel_out.is_none()); + } + } + } else if let Some(kernel_out) = kernel_out { + assert_arrays_eq!(kernel_out, &expected, &mut ctx); + } } } } diff --git a/encodings/onpair/src/tests.rs b/encodings/onpair/src/tests.rs index df07c40a272..27025f960a9 100644 --- a/encodings/onpair/src/tests.rs +++ b/encodings/onpair/src/tests.rs @@ -958,7 +958,14 @@ fn test_onpair_hegel_encoding_harness(tc: TestCase) { #[cfg_attr(miri, ignore)] fn test_onpair_dict_dense_repeated_takes(tc: TestCase) { let mut ctx = SESSION.create_execution_ctx(); - let raw_len = tc.draw(gs::integers::().min_value(1).max_value(48)); + // Draw >= 1024 values (MIN_GATHER_LEN) most of the time so OnPair's specialized TakeExecute + // kernel (both `take_referenced` for dense repeated takes and `take_token_runs`) is exercised. + let large = tc.draw(gs::integers::().max_value(3)) != 0; + let raw_len = if large { + tc.draw(gs::integers::().min_value(1024).max_value(1152)) + } else { + tc.draw(gs::integers::().min_value(1).max_value(48)) + }; let val_nullability = if tc.draw(gs::booleans()) { Nullability::Nullable } else { @@ -968,7 +975,18 @@ fn test_onpair_dict_dense_repeated_takes(tc: TestCase) { let val_mask = val_validity .execute_mask(raw_len, &mut ctx) .vortex_expect("values mask"); - let strings = draw_onpair_strings(&tc, raw_len); + let pool_len = raw_len.min(32); + let pool = draw_onpair_strings(&tc, pool_len); + let strings: Vec = (0..raw_len) + .map(|i| { + let base = &pool[i % pool_len]; + if i < pool_len { + base.clone() + } else { + format!("{base}_{i:04x}") + } + }) + .collect(); let canonical_raw = VarBinViewArray::from_iter( strings .iter() @@ -981,10 +999,12 @@ fn test_onpair_dict_dense_repeated_takes(tc: TestCase) { onpair_compress(&canonical_raw, DEFAULT_CONFIG, &mut ctx).vortex_expect("onpair_compress"); let (encoded_vals, canonical_vals) = if raw_len > 1 && tc.draw(gs::booleans()) { - let start = tc.draw(gs::integers::().max_value(raw_len - 1)); + let min_slice = if large { 1024 } else { 1 }; + let max_start = raw_len - min_slice; + let start = tc.draw(gs::integers::().max_value(max_start)); let end = tc.draw( gs::integers::() - .min_value(start + 1) + .min_value(start + min_slice) .max_value(raw_len), ); ( @@ -1002,25 +1022,39 @@ fn test_onpair_dict_dense_repeated_takes(tc: TestCase) { }; let vals_len = canonical_vals.len(); - // Draw more codes than distinct values so take paths exercise heavy code repetition. - let codes_len = tc.draw(gs::integers::().max_value(160)); - let raw_codes: Vec = if codes_len == 0 { - Vec::new() - } else { - let max_code = u16::try_from(vals_len - 1).vortex_expect("fits u16"); + // Draw dense repeated codes (>= vals_len / 4 when large) so take_referenced is hit. + let codes_len = if large { tc.draw( - gs::vecs(gs::integers::().max_value(max_code)) - .min_size(codes_len) - .max_size(codes_len), + gs::integers::() + .min_value(vals_len / 4) + .max_value(vals_len + 128), ) + } else { + tc.draw(gs::integers::().max_value(160)) + }; + let code_width = tc.draw(gs::integers::().max_value(3)); + let max_code = if code_width == 0 { + u16::try_from((vals_len - 1).min(usize::from(u8::MAX))).vortex_expect("fits u16") + } else { + u16::try_from(vals_len - 1).vortex_expect("fits u16") }; + // Pick a small set of hot indices to guarantee heavy repetition while keeping draws small. + let hot_count = tc.draw(gs::integers::().min_value(1).max_value(16)); + let hot_indices: Vec = tc.draw( + gs::vecs(gs::integers::().max_value(max_code)) + .min_size(hot_count) + .max_size(hot_count), + ); + let raw_codes: Vec = (0..codes_len) + .map(|i| hot_indices[(i.wrapping_mul(7).wrapping_add(i / hot_count)) % hot_count]) + .collect(); let codes_nullability = if tc.draw(gs::booleans()) { Nullability::Nullable } else { Nullability::NonNullable }; let codes_validity = draw_validity_for(&tc, codes_nullability, codes_len); - let codes = match tc.draw(gs::integers::().max_value(3)) { + let codes = match code_width { 0 => PrimitiveArray::new( Buffer::from_iter( raw_codes @@ -1043,10 +1077,22 @@ fn test_onpair_dict_dense_repeated_takes(tc: TestCase) { .into_array(), }; - let dict = DictArray::try_new(codes.clone(), encoded_vals) + let expected = canonical_vals + .take(codes.clone()) + .vortex_expect("canonical take"); + + // Directly exercise OnPair's TakeExecute kernel on the >= 1024-row specialized path. + if vals_len >= 1024 + && let Some(onpair_view) = encoded_vals.as_opt::() + && let Some(taken) = ::take(onpair_view, &codes, &mut ctx) + .vortex_expect("onpair take kernel") + { + assert_arrays_eq!(taken, &expected, &mut ctx); + } + + let dict = DictArray::try_new(codes, encoded_vals) .vortex_expect("dict onpair") .into_array(); - let expected = canonical_vals.take(codes).vortex_expect("canonical take"); let (dict, expected) = if codes_len > 0 && tc.draw(gs::booleans()) { let a = tc.draw(gs::integers::().max_value(codes_len)); diff --git a/encodings/zigzag/src/compress.rs b/encodings/zigzag/src/compress.rs index 6ac460030bf..c40b8cefe04 100644 --- a/encodings/zigzag/src/compress.rs +++ b/encodings/zigzag/src/compress.rs @@ -264,12 +264,24 @@ mod tests { }; // Exercise owned in-place decode (#12048) on a uniquely owned encoded buffer. - let owned_encoded = zigzag_encode(prim.as_view()) - .vortex_expect("zigzag_encode") - .into_array(); + let owned_encoded = zigzag_encode(prim.as_view()).vortex_expect("zigzag_encode"); + let encoded_ptr = owned_encoded + .encoded() + .as_::() + .buffer_handle() + .to_host_sync() + .as_ptr() as usize; let owned_decoded = owned_encoded + .into_array() .execute::(&mut ctx) .vortex_expect("owned zigzag decode"); + if !prim.is_empty() { + assert_eq!( + owned_decoded.buffer_handle().to_host_sync().as_ptr() as usize, + encoded_ptr, + "uniquely owned ZigZagArray should decode in place" + ); + } assert_arrays_eq!(owned_decoded, &prim, &mut ctx); // Exercise shared Arc out-of-place decode, slicing, serde, compare, and chained ops. From 197863398fc68695545ad2836d11e50cb102be50 Mon Sep 17 00:00:00 2001 From: Will Manning Date: Sun, 29 Nov 2026 20:22:37 +0000 Subject: [PATCH 4/4] Require LikeKernel pushdown for all parsed OnPair patterns ContainsScan supports up to 65,535 bytes and a trained OnPair dictionary covers every byte, so merge the Contains arms into the arm expecting pushdown and fix the comments referencing a 254-byte limit. Signed-off-by: Will Manning Co-Authored-By: Will Manning --- encodings/onpair/src/compute/like.rs | 33 +++++++--------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/encodings/onpair/src/compute/like.rs b/encodings/onpair/src/compute/like.rs index 50b8c572500..ba23c35b502 100644 --- a/encodings/onpair/src/compute/like.rs +++ b/encodings/onpair/src/compute/like.rs @@ -307,7 +307,7 @@ mod tests { } /// Differential property test for OnPair `Like` pushdown covering escaped `\%`/`\_`/`\\`, - /// cross-symbol substring boundaries, 254-byte DFA state boundaries, sliced/nullable inputs, + /// cross-symbol substring boundaries, long `ContainsScan` patterns, sliced/nullable inputs, /// and negated/case-insensitive options against canonical `Utf8` `Like`. #[hegel::test(test_cases = 48, print_blob = true)] #[cfg_attr(miri, ignore)] @@ -337,7 +337,7 @@ mod tests { .vortex_expect("validity mask"); let include_long = tc.draw(gs::integers::().max_value(3)) == 0; - let long_base = "ab%cd_ef\\gh".repeat(26); // 286 bytes (> 254-byte DFA boundary) + let long_base = "ab%cd_ef\\gh".repeat(26); // 286 bytes let rows: Vec = (0..len) .map(|i| { if include_long && i == len / 2 { @@ -378,10 +378,9 @@ mod tests { }; // Pick a literal slice from an actual row (crossing token boundaries), an escaped - // metacharacter sequence, or a ~254-byte boundary substring. + // metacharacter sequence, or a long multi-token substring. let sample_row = &rows[tc.draw(gs::integers::().max_value(len - 1))]; - let pattern_branch = tc.draw(gs::integers::().max_value(6)); - let pattern_str = match pattern_branch { + let pattern_str = match tc.draw(gs::integers::().max_value(6)) { 0 => "%".to_owned(), 1 => { // Substring crossing arbitrary char boundaries of a corpus row. @@ -406,7 +405,7 @@ mod tests { } } 2 => { - // Around the 254-byte ContainsScan state limit (250..=260 bytes). + // Long ContainsScan substring (250..=260 bytes). let target_len = tc.draw(gs::integers::().min_value(250).max_value(260)); let sub = &long_base[..target_len.min(long_base.len())]; format!("%{}%", escape_like_literal(sub)) @@ -468,33 +467,17 @@ mod tests { .vortex_expect("like kernel"); if !options.case_insensitive && !is_null_pat { match Pattern::parse(pattern_str.as_bytes()) { - Some(Pattern::Any | Pattern::Equals(_) | Pattern::StartsWith(_)) => { + Some(_) => { let kernel_out = kernel_out .vortex_expect("OnPair LikeKernel should push down parsed pattern"); assert_arrays_eq!(kernel_out, &expected, &mut ctx); } - Some(Pattern::Contains(lit)) - if pattern_branch == 2 - && include_long - && !lit.is_empty() - && lit.len() <= 254 => - { - let kernel_out = kernel_out.vortex_expect( - "OnPair LikeKernel should push down <= 254-byte ContainsScan", - ); - assert_arrays_eq!(kernel_out, &expected, &mut ctx); - } - Some(Pattern::Contains(_)) => { - if let Some(kernel_out) = kernel_out { - assert_arrays_eq!(kernel_out, &expected, &mut ctx); - } - } None => { assert!(kernel_out.is_none()); } } - } else if let Some(kernel_out) = kernel_out { - assert_arrays_eq!(kernel_out, &expected, &mut ctx); + } else { + assert!(kernel_out.is_none()); } } }