From abe5e2d55af7b0f469fffb0511e0b5e2bfc49fbe Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Fri, 24 Oct 2025 20:41:17 +0100 Subject: [PATCH 1/2] chore: use vx array assert eq macro Signed-off-by: Joe Isaacs --- .../fastlanes/src/bitpacking/compress.rs | 4 +- .../fastlanes/src/bitpacking/compute/cast.rs | 5 +- encodings/fastlanes/src/delta/compute/cast.rs | 5 +- encodings/fastlanes/src/delta/ops.rs | 39 +-- encodings/fastlanes/src/for/compress.rs | 13 +- encodings/fastlanes/src/for/compute/cast.rs | 5 +- encodings/fastlanes/src/rle/compress.rs | 42 +-- encodings/fastlanes/src/rle/ops.rs | 8 +- vortex-btrblocks/Cargo.toml | 1 + vortex-btrblocks/src/float.rs | 7 +- vortex-btrblocks/src/float/dictionary.rs | 11 +- vortex-btrblocks/src/integer.rs | 32 ++- vortex-btrblocks/src/integer/dictionary.rs | 11 +- vortex-file/src/tests.rs | 248 ++++++++---------- vortex-layout/src/layouts/chunked/reader.rs | 8 +- vortex-layout/src/layouts/compact.rs | 12 +- vortex-layout/src/layouts/flat/reader.rs | 8 +- vortex-layout/src/layouts/zoned/reader.rs | 8 +- 18 files changed, 228 insertions(+), 239 deletions(-) diff --git a/encodings/fastlanes/src/bitpacking/compress.rs b/encodings/fastlanes/src/bitpacking/compress.rs index de25af4bd6f..3a84b77c671 100644 --- a/encodings/fastlanes/src/bitpacking/compress.rs +++ b/encodings/fastlanes/src/bitpacking/compress.rs @@ -563,8 +563,8 @@ pub mod test_harness { mod test { use rand::SeedableRng as _; use rand::rngs::StdRng; - use vortex_array::ToCanonical as _; use vortex_array::arrays::ChunkedArray; + use vortex_array::{ToCanonical as _, assert_arrays_eq}; use vortex_buffer::{Buffer, buffer}; use vortex_dtype::Nullability; use vortex_error::VortexError; @@ -717,7 +717,7 @@ mod test { let values = PrimitiveArray::from_iter((0..n).map(|i| (i % 2047) as u16)); let compressed = BitPackedArray::encode(values.as_ref(), 11).unwrap(); let decompressed = compressed.to_primitive(); - assert_eq!(decompressed.as_slice::(), values.as_slice::()); + assert_arrays_eq!(decompressed.as_ref(), values.as_ref()); values .as_slice::() diff --git a/encodings/fastlanes/src/bitpacking/compute/cast.rs b/encodings/fastlanes/src/bitpacking/compute/cast.rs index 8f1b403c55c..0498a91d256 100644 --- a/encodings/fastlanes/src/bitpacking/compute/cast.rs +++ b/encodings/fastlanes/src/bitpacking/compute/cast.rs @@ -55,7 +55,7 @@ mod tests { use vortex_array::arrays::PrimitiveArray; use vortex_array::compute::cast; use vortex_array::compute::conformance::cast::test_cast_conformance; - use vortex_array::{IntoArray, ToCanonical}; + use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::buffer; use vortex_dtype::{DType, Nullability, PType}; @@ -78,7 +78,8 @@ mod tests { ); let decoded = casted.to_primitive(); - assert_eq!(decoded.as_slice::(), &[10u32, 20, 30, 40, 50, 60]); + let expected = PrimitiveArray::from_iter([10u32, 20, 30, 40, 50, 60]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] diff --git a/encodings/fastlanes/src/delta/compute/cast.rs b/encodings/fastlanes/src/delta/compute/cast.rs index e397f6921f5..b3ec6c207f2 100644 --- a/encodings/fastlanes/src/delta/compute/cast.rs +++ b/encodings/fastlanes/src/delta/compute/cast.rs @@ -35,10 +35,10 @@ register_kernel!(CastKernelAdapter(DeltaVTable).lift()); #[cfg(test)] mod tests { use rstest::rstest; - use vortex_array::ToCanonical; use vortex_array::arrays::PrimitiveArray; use vortex_array::compute::cast; use vortex_array::compute::conformance::cast::test_cast_conformance; + use vortex_array::{ToCanonical, assert_arrays_eq}; use vortex_buffer::Buffer; use vortex_dtype::{DType, Nullability, PType}; @@ -64,7 +64,8 @@ mod tests { // Verify by decoding let decoded = casted.to_primitive(); - assert_eq!(decoded.as_slice::(), &[10u32, 20, 30, 40, 50]); + let expected = PrimitiveArray::from_iter([10u32, 20, 30, 40, 50]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] diff --git a/encodings/fastlanes/src/delta/ops.rs b/encodings/fastlanes/src/delta/ops.rs index 0cdf2b5a944..489308f5a28 100644 --- a/encodings/fastlanes/src/delta/ops.rs +++ b/encodings/fastlanes/src/delta/ops.rs @@ -46,9 +46,10 @@ impl OperationsVTable for DeltaVTable { #[cfg(test)] mod test { use rstest::rstest; + 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::{IntoArray, ToCanonical}; + use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq}; use super::*; @@ -165,7 +166,9 @@ mod test { let sliced = delta.slice(10..1013); let sliced_again = sliced.slice(0..2); - assert_eq!(sliced_again.to_primitive().as_slice::(), vec![10, 11]); + let decoded = sliced_again.to_primitive(); + let expected = PrimitiveArray::from_iter([10u32, 11]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -175,7 +178,9 @@ mod test { let sliced = delta.slice(10..1013); let sliced_again = sliced.slice(0..2); - assert_eq!(sliced_again.to_primitive().as_slice::(), vec![10, 11]); + let decoded = sliced_again.to_primitive(); + let expected = PrimitiveArray::from_iter([10u32, 11]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -185,10 +190,9 @@ mod test { let sliced = delta.slice(1034..1050); let sliced_again = sliced.slice(0..2); - assert_eq!( - sliced_again.to_primitive().as_slice::(), - vec![1034, 1035] - ); + let decoded = sliced_again.to_primitive(); + let expected = PrimitiveArray::from_iter([1034u32, 1035]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -198,10 +202,9 @@ mod test { let sliced = delta.slice(1034..1050); let sliced_again = sliced.slice(0..2); - assert_eq!( - sliced_again.to_primitive().as_slice::(), - vec![1034, 1035] - ); + let decoded = sliced_again.to_primitive(); + let expected = PrimitiveArray::from_iter([1034u32, 1035]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -211,10 +214,9 @@ mod test { let sliced = delta.slice(1010..1050); let sliced_again = sliced.slice(5..20); - assert_eq!( - sliced_again.to_primitive().as_slice::(), - (1015..1030).collect::>(), - ); + let decoded = sliced_again.to_primitive(); + let expected = PrimitiveArray::from_iter(1015u32..1030); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -224,10 +226,9 @@ mod test { let sliced = delta.slice(1010..1050); let sliced_again = sliced.slice(5..20); - assert_eq!( - sliced_again.to_primitive().as_slice::(), - (1015..1030).collect::>(), - ); + let decoded = sliced_again.to_primitive(); + let expected = PrimitiveArray::from_iter(1015u32..1030); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] diff --git a/encodings/fastlanes/src/for/compress.rs b/encodings/fastlanes/src/for/compress.rs index 4ea106cc559..647ca682f83 100644 --- a/encodings/fastlanes/src/for/compress.rs +++ b/encodings/fastlanes/src/for/compress.rs @@ -157,9 +157,10 @@ fn decompress_primitive( #[cfg(test)] mod test { use itertools::Itertools; - use vortex_array::ToCanonical; + use vortex_array::arrays::PrimitiveArray; use vortex_array::stats::StatsProvider; use vortex_array::validity::Validity; + use vortex_array::{ToCanonical, assert_arrays_eq}; use vortex_buffer::buffer; use vortex_dtype::PType; use vortex_scalar::Scalar; @@ -173,7 +174,7 @@ mod test { assert_eq!(i32::try_from(compressed.reference_scalar()).unwrap(), 1); let decompressed = compressed.to_primitive(); - assert_eq!(decompressed.as_slice::(), array.as_slice::()); + assert_arrays_eq!(decompressed.as_ref(), array.as_ref()); } #[test] @@ -211,7 +212,7 @@ mod test { let array = PrimitiveArray::from_iter((0u32..100_000).step_by(1024).map(|v| v + 1_000_000)); let compressed = FoRArray::encode(array.clone()).unwrap(); let decompressed = compressed.to_primitive(); - assert_eq!(decompressed.as_slice::(), array.as_slice::()); + assert_arrays_eq!(decompressed.as_ref(), array.as_ref()); } #[test] @@ -222,7 +223,7 @@ mod test { let bp = BitPackedArray::encode(array.as_ref(), 3).unwrap(); let compressed = FoRArray::try_new(bp.into_array(), 10u32.into()).unwrap(); let decompressed = compressed.to_primitive(); - assert_eq!(decompressed.as_slice::(), expect.as_slice::()); + assert_arrays_eq!(decompressed.as_ref(), expect.as_ref()); } #[test] @@ -233,7 +234,7 @@ mod test { let bp = BitPackedArray::encode(array.as_ref(), 2).unwrap(); let compressed = FoRArray::try_new(bp.clone().into_array(), 10u32.into()).unwrap(); let decompressed = fused_decompress::(&compressed, &bp); - assert_eq!(decompressed.as_slice::(), expect.as_slice::()); + assert_arrays_eq!(decompressed.as_ref(), expect.as_ref()); } #[test] @@ -258,7 +259,7 @@ mod test { assert_eq!(encoded_bytes, unsigned.as_slice()); let decompressed = compressed.to_primitive(); - assert_eq!(decompressed.as_slice::(), array.as_slice::()); + assert_arrays_eq!(decompressed.as_ref(), array.as_ref()); array .as_slice::() .iter() diff --git a/encodings/fastlanes/src/for/compute/cast.rs b/encodings/fastlanes/src/for/compute/cast.rs index 75f56898b2b..8f6deaf7c05 100644 --- a/encodings/fastlanes/src/for/compute/cast.rs +++ b/encodings/fastlanes/src/for/compute/cast.rs @@ -33,7 +33,7 @@ mod tests { use vortex_array::arrays::PrimitiveArray; use vortex_array::compute::cast; use vortex_array::compute::conformance::cast::test_cast_conformance; - use vortex_array::{IntoArray, ToCanonical}; + use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::buffer; use vortex_dtype::{DType, Nullability, PType}; use vortex_scalar::Scalar; @@ -60,7 +60,8 @@ mod tests { // Verify the values after decoding let decoded = casted.to_primitive(); - assert_eq!(decoded.as_slice::(), &[100i64, 110, 120, 130, 140]); + let expected = PrimitiveArray::from_iter([100i64, 110, 120, 130, 140]); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] diff --git a/encodings/fastlanes/src/rle/compress.rs b/encodings/fastlanes/src/rle/compress.rs index b8e6de7ccb2..c30a918d145 100644 --- a/encodings/fastlanes/src/rle/compress.rs +++ b/encodings/fastlanes/src/rle/compress.rs @@ -204,7 +204,7 @@ where #[cfg(test)] mod test { use rstest::rstest; - use vortex_array::{IntoArray, ToCanonical}; + use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::Buffer; use vortex_dtype::half::f16; @@ -214,24 +214,27 @@ mod test { fn test_encode_decode() { // u8 let values_u8: Buffer = [1, 1, 2, 2, 3, 3].iter().copied().collect(); - let array_u8 = values_u8.into_array(); + let array_u8 = values_u8.clone().into_array(); let encoded_u8 = RLEArray::encode(&array_u8.to_primitive()).unwrap(); let decoded_u8 = encoded_u8.to_primitive(); - assert_eq!(decoded_u8.as_slice::(), &[1, 1, 2, 2, 3, 3]); + let expected_u8 = values_u8.into_array(); + assert_arrays_eq!(decoded_u8.as_ref(), expected_u8.as_ref()); // u16 let values_u16: Buffer = [100, 100, 200, 200].iter().copied().collect(); - let array_u16 = values_u16.into_array(); + let array_u16 = values_u16.clone().into_array(); let encoded_u16 = RLEArray::encode(&array_u16.to_primitive()).unwrap(); let decoded_u16 = encoded_u16.to_primitive(); - assert_eq!(decoded_u16.as_slice::(), &[100, 100, 200, 200]); + let expected_u16 = values_u16.into_array(); + assert_arrays_eq!(decoded_u16.as_ref(), expected_u16.as_ref()); // u64 let values_u64: Buffer = [1000, 1000, 2000].iter().copied().collect(); - let array_u64 = values_u64.into_array(); + let array_u64 = values_u64.clone().into_array(); let encoded_u64 = RLEArray::encode(&array_u64.to_primitive()).unwrap(); let decoded_u64 = encoded_u64.to_primitive(); - assert_eq!(decoded_u64.as_slice::(), &[1000, 1000, 2000]); + let expected_u64 = values_u64.into_array(); + assert_arrays_eq!(decoded_u64.as_ref(), expected_u64.as_ref()); } #[test] @@ -255,39 +258,41 @@ mod test { #[test] fn test_single_value() { let values: Buffer = vec![42; 2000].into_iter().collect(); - let array = values.into_array(); + let array = values.clone().into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); assert_eq!(encoded.values.len(), 2); // 2 chunks, each storing value 42 let decoded = encoded.to_primitive(); // Verify round-trip - assert_eq!(decoded.as_slice::(), &vec![42; 2000]); + let expected = values.into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] fn test_all_different() { let values: Buffer = (0u8..=255).collect(); - let array = values.into_array(); + let array = values.clone().into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); assert_eq!(encoded.values.len(), 256); let decoded = encoded.to_primitive(); // Verify round-trip - assert_eq!(decoded.as_slice::(), &(0u8..=255).collect::>()); + let expected = values.into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] fn test_partial_last_chunk() { // Test array with partial last chunk (not divisible by 1024) let values: Buffer = (0..1500).map(|i| (i / 100) as u32).collect(); - let expected: Vec = (0..1500).map(|i| (i / 100) as u32).collect(); - let array = values.into_array(); + let array = values.clone().into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); let decoded = encoded.to_primitive(); assert_eq!(encoded.len(), 1500); - assert_eq!(decoded.as_slice::(), expected.as_slice()); + let expected = values.into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); // 2 chunks: 1024 + 476 elements assert_eq!(encoded.values_idx_offsets().len(), 2); } @@ -296,14 +301,14 @@ mod test { fn test_two_full_chunks() { // Array that spans exactly 2 chunks (2048 elements) let values: Buffer = (0..2048).map(|i| (i / 100) as u32).collect(); - let expected: Vec = (0..2048).map(|i| (i / 100) as u32).collect(); - let array = values.into_array(); + let array = values.clone().into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); let decoded = encoded.to_primitive(); assert_eq!(encoded.len(), 2048); - assert_eq!(decoded.as_slice::(), expected.as_slice()); + let expected = values.into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); assert_eq!(encoded.values_idx_offsets().len(), 2); } @@ -323,6 +328,7 @@ mod test { let primitive = values.clone().into_array().to_primitive(); let result = RLEArray::encode(&primitive).unwrap(); let decoded = result.to_primitive(); - assert_eq!(decoded.as_slice::(), values.as_slice()); + let expected = values.into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } } diff --git a/encodings/fastlanes/src/rle/ops.rs b/encodings/fastlanes/src/rle/ops.rs index d630b91eecf..78869c8933c 100644 --- a/encodings/fastlanes/src/rle/ops.rs +++ b/encodings/fastlanes/src/rle/ops.rs @@ -72,7 +72,7 @@ impl OperationsVTable for RLEVTable { mod tests { use vortex_array::arrays::PrimitiveArray; use vortex_array::validity::Validity; - use vortex_array::{Array, IntoArray, ToCanonical}; + use vortex_array::{Array, IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::Buffer; use super::*; @@ -311,11 +311,13 @@ mod tests { // Slice across first and second chunk. let slice = encoded.slice(500..1500); let decoded_slice = slice.to_primitive(); - assert_eq!(decoded_slice.as_slice::(), &expected[500..1500]); + let expected_slice = PrimitiveArray::from_iter(expected[500..1500].iter().copied()); + assert_arrays_eq!(decoded_slice.as_ref(), expected_slice.as_ref()); // Slice across second and third chunk. let slice = encoded.slice(1000..2000); let decoded_slice = slice.to_primitive(); - assert_eq!(decoded_slice.as_slice::(), &expected[1000..2000]); + let expected_slice = PrimitiveArray::from_iter(expected[1000..2000].iter().copied()); + assert_arrays_eq!(decoded_slice.as_ref(), expected_slice.as_ref()); } } diff --git a/vortex-btrblocks/Cargo.toml b/vortex-btrblocks/Cargo.toml index 2f59ad2c273..d7fcb57b3d4 100644 --- a/vortex-btrblocks/Cargo.toml +++ b/vortex-btrblocks/Cargo.toml @@ -41,6 +41,7 @@ vortex-zigzag = { workspace = true } [dev-dependencies] divan = { workspace = true } env_logger = "0.11" +vortex-array = { workspace = true, features = ["test-harness"] } [features] # This feature enabled unstable encodings for which we don't guarantee stability. diff --git a/vortex-btrblocks/src/float.rs b/vortex-btrblocks/src/float.rs index 5f87efebf41..beeb7a05860 100644 --- a/vortex-btrblocks/src/float.rs +++ b/vortex-btrblocks/src/float.rs @@ -379,7 +379,7 @@ mod tests { use vortex_array::arrays::PrimitiveArray; use vortex_array::validity::Validity; - use vortex_array::{Array, IntoArray, ToCanonical}; + use vortex_array::{Array, IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::{Buffer, buffer_mut}; use crate::float::{FloatCompressor, RLE_FLOAT_SCHEME}; @@ -426,7 +426,8 @@ mod tests { let stats = crate::float::FloatStats::generate(&array); let compressed = RLE_FLOAT_SCHEME.compress(&stats, false, 3, &[]).unwrap(); - let decoded = compressed.to_primitive(); - assert_eq!(decoded.as_slice::(), values.as_slice()); + let decoded = compressed; + let expected = Buffer::copy_from(&values).into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } } diff --git a/vortex-btrblocks/src/float/dictionary.rs b/vortex-btrblocks/src/float/dictionary.rs index 96d05d777f2..d935181bb73 100644 --- a/vortex-btrblocks/src/float/dictionary.rs +++ b/vortex-btrblocks/src/float/dictionary.rs @@ -97,7 +97,7 @@ impl_encode!(f64, u64); mod tests { use vortex_array::arrays::{BoolArray, PrimitiveArray}; use vortex_array::validity::Validity; - use vortex_array::{Array, IntoArray, ToCanonical}; + use vortex_array::{Array, IntoArray, assert_arrays_eq}; use vortex_buffer::buffer; use crate::CompressorStats; @@ -117,10 +117,15 @@ mod tests { assert_eq!(dict_array.values().len(), 2); assert_eq!(dict_array.codes().len(), 5); - let undict = dict_array.to_primitive(); + let undict = dict_array; // We just use code zero but it doesn't really matter. // We can just shove a whole validity buffer in there instead. - assert_eq!(undict.as_slice::(), &[1f32, 2f32, 2f32, 1f32, 1f32]); + let expected = PrimitiveArray::new( + buffer![1f32, 2f32, 2f32, 1f32, 1f32], + Validity::Array(BoolArray::from_iter([true, true, true, false, true]).into_array()), + ) + .into_array(); + assert_arrays_eq!(undict.as_ref(), expected.as_ref()); } } diff --git a/vortex-btrblocks/src/integer.rs b/vortex-btrblocks/src/integer.rs index 36bad3f5535..3f56db233b2 100644 --- a/vortex-btrblocks/src/integer.rs +++ b/vortex-btrblocks/src/integer.rs @@ -758,7 +758,7 @@ mod tests { use vortex_array::arrays::PrimitiveArray; use vortex_array::validity::Validity; use vortex_array::vtable::ValidityHelper; - use vortex_array::{Array, IntoArray, ToCanonical}; + use vortex_array::{Array, IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::{Buffer, BufferMut, buffer, buffer_mut}; use vortex_dict::DictEncoding; use vortex_sequence::SequenceEncoding; @@ -845,10 +845,11 @@ mod tests { .compress(&IntegerStats::generate(&array), false, 3, &[]) .unwrap(); assert_eq!(compressed.encoding_id(), SparseEncoding.id()); - let decoded = compressed.to_primitive(); - let expected = [189u8, 189, 189, 0, 0]; - assert_eq!(decoded.as_slice::(), &expected); - assert_eq!(decoded.validity(), array.validity()); + let decoded = compressed.clone(); + let expected = + PrimitiveArray::new(buffer![189u8, 189, 189, 0, 0], array.validity().clone()) + .into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -863,10 +864,13 @@ mod tests { .compress(&IntegerStats::generate(&array), false, 3, &[]) .unwrap(); assert_eq!(compressed.encoding_id(), SparseEncoding.id()); - let decoded = compressed.to_primitive(); - let expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46]; - assert_eq!(decoded.as_slice::(), &expected); - assert_eq!(decoded.validity(), array.validity()); + let decoded = compressed.clone(); + let expected = PrimitiveArray::new( + buffer![0u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46], + array.validity().clone(), + ) + .into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -877,8 +881,9 @@ mod tests { .compress(&IntegerStats::generate(&array), false, 3, &[]) .unwrap(); assert_eq!(compressed.encoding_id(), SequenceEncoding.id()); - let decoded = compressed.to_primitive(); - assert_eq!(decoded.as_slice::(), values.as_slice()); + let decoded = compressed; + let expected = PrimitiveArray::from_option_iter(values.into_iter().map(Some)).into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } #[test] @@ -893,7 +898,8 @@ mod tests { .compress(&IntegerStats::generate(&array), false, 3, &[]) .unwrap(); - let decoded = compressed.to_primitive(); - assert_eq!(decoded.as_slice::(), values.as_slice()); + let decoded = compressed; + let expected = Buffer::copy_from(&values).into_array(); + assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); } } diff --git a/vortex-btrblocks/src/integer/dictionary.rs b/vortex-btrblocks/src/integer/dictionary.rs index 5e3592de722..6224ab174dc 100644 --- a/vortex-btrblocks/src/integer/dictionary.rs +++ b/vortex-btrblocks/src/integer/dictionary.rs @@ -111,7 +111,7 @@ impl_encode!(i64); mod tests { use vortex_array::arrays::{BoolArray, PrimitiveArray}; use vortex_array::validity::Validity; - use vortex_array::{Array, IntoArray, ToCanonical}; + use vortex_array::{Array, IntoArray, assert_arrays_eq}; use vortex_buffer::buffer; use crate::CompressorStats; @@ -131,10 +131,15 @@ mod tests { assert_eq!(dict_array.values().len(), 2); assert_eq!(dict_array.codes().len(), 5); - let undict = dict_array.to_primitive(); + let undict = dict_array; // We just use code zero, but it doesn't really matter. // We can just shove a whole validity buffer in there instead. - assert_eq!(undict.as_slice::(), &[100i32, 200, 100, 100, 100]); + let expected = PrimitiveArray::new( + buffer![100i32, 200, 100, 100, 100], + Validity::Array(BoolArray::from_iter([true, true, true, false, true]).into_array()), + ) + .into_array(); + assert_arrays_eq!(undict.as_ref(), expected.as_ref()); } } diff --git a/vortex-file/src/tests.rs b/vortex-file/src/tests.rs index 1e6eef05e49..6958af263ad 100644 --- a/vortex-file/src/tests.rs +++ b/vortex-file/src/tests.rs @@ -16,7 +16,7 @@ use vortex_array::arrays::{ use vortex_array::stats::PRUNING_STATS; use vortex_array::stream::{ArrayStreamAdapter, ArrayStreamExt}; use vortex_array::validity::Validity; -use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical}; +use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::{Buffer, ByteBufferMut, buffer}; use vortex_dict::{DictEncoding, DictVTable}; use vortex_dtype::PType::I32; @@ -240,14 +240,9 @@ async fn test_read_projection() { ) ); - let actual = array.to_struct().fields()[0] - .to_varbinview() - .with_iterator(|x| { - x.map(|x| unsafe { String::from_utf8_unchecked(x.unwrap().to_vec()) }) - .collect::>() - }) - .unwrap(); - assert_eq!(actual, strings_expected); + let actual = array.to_struct().fields()[0].clone(); + let expected = VarBinArray::from(strings_expected.to_vec()).into_array(); + assert_arrays_eq!(actual.as_ref(), expected.as_ref()); let array = file .scan() @@ -267,9 +262,9 @@ async fn test_read_projection() { ) ); - let primitive_array = array.to_struct().fields()[0].to_primitive(); - let actual = primitive_array.as_slice::(); - assert_eq!(actual, numbers_expected); + let actual = array.to_struct().fields()[0].clone(); + let expected = Buffer::copy_from(numbers_expected).into_array(); + assert_arrays_eq!(actual.as_ref(), expected.as_ref()); } #[tokio::test] @@ -433,19 +428,15 @@ async fn filter_string() { .unwrap(); assert_eq!(result.len(), 1); - let names = result[0].to_struct().fields()[0].clone(); - assert_eq!( - names - .to_varbinview() - .with_iterator(|iter| iter - .flatten() - .map(|s| unsafe { String::from_utf8_unchecked(s.to_vec()) }) - .collect::>()) - .unwrap(), - vec!["Joseph".to_string()] - ); - let ages = result[0].to_struct().fields()[1].clone(); - assert_eq!(ages.to_primitive().as_slice::(), vec![25]); + let names_actual = result[0].to_struct().fields()[0].clone(); + let names_expected = + VarBinArray::from_iter(vec![Some("Joseph")], DType::Utf8(Nullability::Nullable)) + .into_array(); + assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); + + let ages_actual = result[0].to_struct().fields()[1].clone(); + let ages_expected = PrimitiveArray::from_option_iter([Some(25i32)]).into_array(); + assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } #[tokio::test] @@ -549,18 +540,17 @@ async fn filter_and() { .unwrap(); assert_eq!(result.len(), 1); - let names = result[0].to_struct().fields()[0].clone(); - assert_eq!( - names - .to_varbinview() - .with_iterator(|iter| iter - .map(|s| s.map(|st| unsafe { String::from_utf8_unchecked(st.to_vec()) })) - .collect::>()) - .unwrap(), - vec![Some("Joseph".to_string()), None] - ); - let ages = result[0].to_struct().fields()[1].clone(); - assert_eq!(ages.to_primitive().as_slice::(), vec![25, 31]); + let names_actual = result[0].to_struct().fields()[0].clone(); + let names_expected = VarBinArray::from_iter( + vec![Some("Joseph"), None], + DType::Utf8(Nullability::Nullable), + ) + .into_array(); + assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); + + let ages_actual = result[0].to_struct().fields()[1].clone(); + let ages_expected = PrimitiveArray::from_option_iter([Some(25i32), Some(31i32)]).into_array(); + assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } #[tokio::test] @@ -621,9 +611,8 @@ async fn test_with_indices_simple() { .iter() .map(|&x| expected_numbers[x as usize]) .collect(); - let actual_kept_numbers = actual_kept_numbers_array.as_slice::(); - - assert_eq!(expected_kept_numbers, actual_kept_numbers); + let expected_array = Buffer::copy_from(&expected_kept_numbers).into_array(); + assert_arrays_eq!(actual_kept_numbers_array.as_ref(), expected_array.as_ref()); // test all indices let actual_array = file @@ -636,10 +625,9 @@ async fn test_with_indices_simple() { .await .unwrap() .to_struct(); - let actual_numbers_array = actual_array.fields()[0].to_primitive(); - let actual_numbers = actual_numbers_array.as_slice::(); - - assert_eq!(expected_numbers, actual_numbers); + let actual_numbers_array = actual_array.fields()[0].clone(); + let expected_array = Buffer::copy_from(&expected_numbers).into_array(); + assert_arrays_eq!(actual_numbers_array.as_ref(), expected_array.as_ref()); } #[tokio::test] @@ -681,30 +669,21 @@ async fn test_with_indices_on_two_columns() { .to_struct() .to_struct(); - let strings_actual = array.fields()[0] - .to_varbinview() - .with_iterator(|x| { - x.map(|x| unsafe { String::from_utf8_unchecked(x.unwrap().to_vec()) }) - .collect::>() - }) - .unwrap(); - assert_eq!( - strings_actual, - kept_indices - .iter() - .map(|&x| strings_expected[x as usize]) - .collect::>() - ); + let strings_actual = array.fields()[0].clone(); + let strings_expected_vec: Vec<&str> = kept_indices + .iter() + .map(|&x| strings_expected[x as usize]) + .collect(); + let strings_expected_array = VarBinArray::from(strings_expected_vec).into_array(); + assert_arrays_eq!(strings_actual.as_ref(), strings_expected_array.as_ref()); - let numbers_actual_array = array.fields()[1].to_primitive(); - let numbers_actual = numbers_actual_array.as_slice::(); - assert_eq!( - numbers_actual, - kept_indices - .iter() - .map(|&x| numbers_expected[x as usize]) - .collect::>() - ); + let numbers_actual = array.fields()[1].clone(); + let numbers_expected_vec: Vec = kept_indices + .iter() + .map(|&x| numbers_expected[x as usize]) + .collect(); + let numbers_expected_array = Buffer::copy_from(&numbers_expected_vec).into_array(); + assert_arrays_eq!(numbers_actual.as_ref(), numbers_expected_array.as_ref()); } #[tokio::test] @@ -768,9 +747,8 @@ async fn test_with_indices_and_with_row_filter_simple() { .map(|&x| expected_numbers[x as usize]) .filter(|&x| x > 50) .collect(); - let actual_kept_numbers = actual_kept_numbers_array.as_slice::(); - - assert_eq!(expected_kept_numbers.as_slice(), actual_kept_numbers); + let expected_array = expected_kept_numbers.into_array(); + assert_arrays_eq!(actual_kept_numbers_array.as_ref(), expected_array.as_ref()); // test all indices let actual_array = file @@ -847,19 +825,15 @@ async fn filter_string_chunked() { .to_struct(); assert_eq!(actual_array.len(), 1); - let names = &actual_array.fields()[0]; - assert_eq!( - names - .to_varbinview() - .with_iterator(|iter| iter - .flatten() - .map(|s| unsafe { String::from_utf8_unchecked(s.to_vec()) }) - .collect::>()) - .unwrap(), - vec!["Joseph".to_string()] - ); - let ages = &actual_array.fields()[1]; - assert_eq!(ages.to_primitive().as_slice::(), vec![25]); + let names_actual = actual_array.fields()[0].clone(); + let names_expected = + VarBinArray::from_iter(vec![Some("Joseph")], DType::Utf8(Nullability::Nullable)) + .into_array(); + assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); + + let ages_actual = actual_array.fields()[1].clone(); + let ages_expected = PrimitiveArray::from_option_iter([Some(25i32)]).into_array(); + assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } #[tokio::test] @@ -941,47 +915,37 @@ async fn test_pruning_with_or() { .to_struct(); assert_eq!(actual_array.len(), 10); - let letters = &actual_array.fields()[0]; - assert_eq!( - letters - .to_varbinview() - .with_iterator(|iter| iter - .map(|opt| opt.map(|s| unsafe { String::from_utf8_unchecked(s.to_vec()) })) - .collect::>()) - .unwrap(), - vec![ - Some("A".to_string()), - Some("B".to_string()), - Some("D".to_string()), - Some("G".to_string()), - Some("I".to_string()), - Some("J".to_string()), - None, - Some("L".to_string()), - None, - Some("P".to_string()) - ] - ); - let numbers = &actual_array.fields()[1]; - assert_eq!( - (0..numbers.len()) - .map(|index| -> Option { - numbers.scalar_at(index).as_primitive().typed_value::() - }) - .collect::>(), - vec![ - Some(25), - Some(31), - None, - Some(4), - Some(18), - None, - Some(21), - Some(10), - Some(15), - Some(22) - ] - ); + let letters_actual = actual_array.fields()[0].clone(); + let letters_expected = VarBinViewArray::from_iter_nullable_str([ + Some("A".to_owned()), + Some("B".to_owned()), + Some("D".to_owned()), + Some("G".to_owned()), + Some("I".to_owned()), + Some("J".to_owned()), + None, + Some("L".to_owned()), + None, + Some("P".to_owned()), + ]) + .into_array(); + assert_arrays_eq!(letters_actual.as_ref(), letters_expected.as_ref()); + + let numbers_actual = actual_array.fields()[1].clone(); + let numbers_expected = PrimitiveArray::from_option_iter([ + Some(25_i32), + Some(31), + None, + Some(4), + Some(18), + None, + Some(21), + Some(10), + Some(15), + Some(22), + ]) + .into_array(); + assert_arrays_eq!(numbers_actual.as_ref(), numbers_expected.as_ref()); } #[tokio::test] @@ -1048,14 +1012,10 @@ async fn chunked_file() -> VortexResult { #[tokio::test] async fn basic_file_roundtrip() -> VortexResult<()> { let vxf = chunked_file().await?; - let result = vxf - .scan()? - .into_array_stream()? - .read_all() - .await? - .to_primitive(); + let result = vxf.scan()?.into_array_stream()?.read_all().await?; - assert_eq!(result.as_slice::(), &[0, 1, 2, 3, 4, 5, 6, 7, 8]); + let expected = buffer![0i32, 1, 2, 3, 4, 5, 6, 7, 8].into_array(); + assert_arrays_eq!(result.as_ref(), expected.as_ref()); Ok(()) } @@ -1098,10 +1058,10 @@ async fn file_take() -> VortexResult<()> { .with_row_indices(buffer![0, 1, 8]) .into_array_stream()? .read_all() - .await? - .to_primitive(); + .await?; - assert_eq!(result.as_slice::(), &[0, 1, 8]); + let expected = buffer![0i32, 1, 8].into_array(); + assert_arrays_eq!(result.as_ref(), expected.as_ref()); Ok(()) } @@ -1305,8 +1265,9 @@ async fn test_writer_multiple_pushes() -> VortexResult<()> { let result = file.scan()?.into_array_stream()?.read_all().await?; assert_eq!(result.len(), 9); - let numbers = result.to_struct().field_by_name("numbers")?.to_primitive(); - assert_eq!(numbers.as_slice::(), &[1, 2, 3, 4, 5, 6, 7, 8, 9]); + let numbers = result.to_struct().field_by_name("numbers")?.clone(); + let expected = buffer![1u32, 2, 3, 4, 5, 6, 7, 8, 9].into_array(); + assert_arrays_eq!(numbers.as_ref(), expected.as_ref()); Ok(()) } @@ -1335,8 +1296,9 @@ async fn test_writer_push_stream() -> VortexResult<()> { let result = file.scan()?.into_array_stream()?.read_all().await?; assert_eq!(result.len(), 6); - let numbers = result.to_struct().field_by_name("numbers")?.to_primitive(); - assert_eq!(numbers.as_slice::(), &[1, 2, 3, 4, 5, 6]); + let numbers = result.to_struct().field_by_name("numbers")?.clone(); + let expected = buffer![1u32, 2, 3, 4, 5, 6].into_array(); + assert_arrays_eq!(numbers.as_ref(), expected.as_ref()); Ok(()) } @@ -1395,8 +1357,9 @@ async fn test_writer_empty_chunks() -> VortexResult<()> { let result = file.scan()?.into_array_stream()?.read_all().await?; assert_eq!(result.len(), 2); - let numbers = result.to_struct().field_by_name("numbers")?.to_primitive(); - assert_eq!(numbers.as_slice::(), &[1, 2]); + let numbers = result.to_struct().field_by_name("numbers")?.clone(); + let expected = buffer![1u32, 2].into_array(); + assert_arrays_eq!(numbers.as_ref(), expected.as_ref()); Ok(()) } @@ -1429,8 +1392,9 @@ async fn test_writer_mixed_push_and_stream() -> VortexResult<()> { let result = file.scan()?.into_array_stream()?.read_all().await?; assert_eq!(result.len(), 6); - let numbers = result.to_struct().field_by_name("numbers")?.to_primitive(); - assert_eq!(numbers.as_slice::(), &[1, 2, 3, 4, 5, 6]); + let numbers = result.to_struct().field_by_name("numbers")?.clone(); + let expected = buffer![1u32, 2, 3, 4, 5, 6].into_array(); + assert_arrays_eq!(numbers.as_ref(), expected.as_ref()); Ok(()) } diff --git a/vortex-layout/src/layouts/chunked/reader.rs b/vortex-layout/src/layouts/chunked/reader.rs index 83e1cfd7f2e..426c9b169cb 100644 --- a/vortex-layout/src/layouts/chunked/reader.rs +++ b/vortex-layout/src/layouts/chunked/reader.rs @@ -269,7 +269,7 @@ mod test { use futures::stream; use rstest::{fixture, rstest}; - use vortex_array::{ArrayContext, IntoArray, MaskFuture, ToCanonical}; + use vortex_array::{ArrayContext, IntoArray, MaskFuture, assert_arrays_eq}; use vortex_buffer::buffer; use vortex_dtype::Nullability::NonNullable; use vortex_dtype::{DType, PType}; @@ -326,11 +326,11 @@ mod test { ) .unwrap() .await - .unwrap() - .to_primitive(); + .unwrap(); assert_eq!(result.len(), 9); - assert_eq!(result.as_slice::(), &[1, 2, 3, 4, 5, 6, 7, 8, 9]); + let expected = buffer![1i32, 2, 3, 4, 5, 6, 7, 8, 9].into_array(); + assert_arrays_eq!(result.as_ref(), expected.as_ref()); }) } } diff --git a/vortex-layout/src/layouts/compact.rs b/vortex-layout/src/layouts/compact.rs index 40f20bba4e2..c8a9fec2c66 100644 --- a/vortex-layout/src/layouts/compact.rs +++ b/vortex-layout/src/layouts/compact.rs @@ -194,7 +194,7 @@ impl Default for CompactCompressor { mod tests { use vortex_array::arrays::{PrimitiveArray, StructArray}; use vortex_array::validity::Validity; - use vortex_array::{IntoArray, ToCanonical}; + use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq}; use vortex_buffer::buffer; use vortex_dtype::FieldName; @@ -238,16 +238,10 @@ mod tests { // Verify each field can be accessed and has correct data for (i, name) in decompressed_struct.names().iter().enumerate() { assert_eq!(name, field_names[i]); - let decompressed_array = decompressed_struct - .field_by_name(name) - .unwrap() - .to_primitive(); - // is there no direct way to assert_eq on (primitive) arrays? + let decompressed_array = decompressed_struct.field_by_name(name).unwrap().clone(); assert_eq!(decompressed_array.len(), n_rows); - for j in 0..n_rows { - assert_eq!(decompressed_array.scalar_at(j), columns[i].scalar_at(j),); - } + assert_arrays_eq!(decompressed_array.as_ref(), columns[i].as_ref()); } } } diff --git a/vortex-layout/src/layouts/flat/reader.rs b/vortex-layout/src/layouts/flat/reader.rs index f17232a7280..1d3952d142f 100644 --- a/vortex-layout/src/layouts/flat/reader.rs +++ b/vortex-layout/src/layouts/flat/reader.rs @@ -260,7 +260,7 @@ mod test { use vortex_array::arrays::PrimitiveArray; use vortex_array::validity::Validity; - use vortex_array::{ArrayContext, MaskFuture, ToCanonical}; + use vortex_array::{ArrayContext, IntoArray, MaskFuture, ToCanonical, assert_arrays_eq}; use vortex_buffer::{BitBuffer, buffer}; use vortex_expr::{gt, lit, root}; use vortex_io::runtime::single::block_on; @@ -371,10 +371,10 @@ mod test { .projection_evaluation(&(2..4), &root(), MaskFuture::new_true(2)) .unwrap() .await - .unwrap() - .to_primitive(); + .unwrap(); - assert_eq!(result.as_slice::(), &[3, 4],); + let expected = PrimitiveArray::new(buffer![3i32, 4], Validity::AllValid).into_array(); + assert_arrays_eq!(result.as_ref(), expected.as_ref()); }) } } diff --git a/vortex-layout/src/layouts/zoned/reader.rs b/vortex-layout/src/layouts/zoned/reader.rs index 001a901714d..bab801f7a1f 100644 --- a/vortex-layout/src/layouts/zoned/reader.rs +++ b/vortex-layout/src/layouts/zoned/reader.rs @@ -352,7 +352,7 @@ mod test { use rstest::{fixture, rstest}; use vortex_array::arrays::ChunkedArray; - use vortex_array::{ArrayContext, IntoArray, MaskFuture, ToCanonical}; + use vortex_array::{ArrayContext, IntoArray, MaskFuture, assert_arrays_eq}; use vortex_buffer::buffer; use vortex_expr::{gt, lit, root}; use vortex_io::runtime::single::block_on; @@ -409,11 +409,11 @@ mod test { ) .unwrap() .await - .unwrap() - .to_primitive(); + .unwrap(); assert_eq!(result.len(), 9); - assert_eq!(result.as_slice::(), &[1, 2, 3, 4, 5, 6, 7, 8, 9]); + let expected = buffer![1i32, 2, 3, 4, 5, 6, 7, 8, 9].into_array(); + assert_arrays_eq!(result.as_ref(), expected.as_ref()); }) } From 154ada05db30834d6d5223fd8f6a7232da57631b Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Mon, 27 Oct 2025 17:36:52 +0000 Subject: [PATCH 2/2] chore: use vx array assert eq macro Signed-off-by: Joe Isaacs --- encodings/fastlanes/src/rle/compress.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/encodings/fastlanes/src/rle/compress.rs b/encodings/fastlanes/src/rle/compress.rs index 3d438d9c5e7..3fe5f3f5e85 100644 --- a/encodings/fastlanes/src/rle/compress.rs +++ b/encodings/fastlanes/src/rle/compress.rs @@ -214,7 +214,7 @@ mod test { fn test_encode_decode() { // u8 let values_u8: Buffer = [1, 1, 2, 2, 3, 3].iter().copied().collect(); - let array_u8 = values_u8.clone().into_array(); + let array_u8 = values_u8.into_array(); let encoded_u8 = RLEArray::encode(&array_u8.to_primitive()).unwrap(); let decoded_u8 = encoded_u8.to_primitive(); let expected_u8 = PrimitiveArray::from_iter(vec![1u8, 1, 2, 2, 3, 3]); @@ -222,7 +222,7 @@ mod test { // u16 let values_u16: Buffer = [100, 100, 200, 200].iter().copied().collect(); - let array_u16 = values_u16.clone().into_array(); + let array_u16 = values_u16.into_array(); let encoded_u16 = RLEArray::encode(&array_u16.to_primitive()).unwrap(); let decoded_u16 = encoded_u16.to_primitive(); let expected_u16 = PrimitiveArray::from_iter(vec![100u16, 100, 200, 200]); @@ -230,7 +230,7 @@ mod test { // u64 let values_u64: Buffer = [1000, 1000, 2000].iter().copied().collect(); - let array_u64 = values_u64.clone().into_array(); + let array_u64 = values_u64.into_array(); let encoded_u64 = RLEArray::encode(&array_u64.to_primitive()).unwrap(); let decoded_u64 = encoded_u64.to_primitive(); let expected_u64 = PrimitiveArray::from_iter(vec![1000u64, 1000, 2000]); @@ -258,7 +258,7 @@ mod test { #[test] fn test_single_value() { let values: Buffer = vec![42; 2000].into_iter().collect(); - let array = values.clone().into_array(); + let array = values.into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); assert_eq!(encoded.values.len(), 2); // 2 chunks, each storing value 42 @@ -271,7 +271,7 @@ mod test { #[test] fn test_all_different() { let values: Buffer = (0u8..=255).collect(); - let array = values.clone().into_array(); + let array = values.into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); assert_eq!(encoded.values.len(), 256); @@ -285,14 +285,13 @@ mod test { fn test_partial_last_chunk() { // Test array with partial last chunk (not divisible by 1024) let values: Buffer = (0..1500).map(|i| (i / 100) as u32).collect(); - let array = values.clone().into_array(); + let array = values.into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); let decoded = encoded.to_primitive(); assert_eq!(encoded.len(), 1500); - let expected_array = PrimitiveArray::from_iter(expected); - assert_arrays_eq!(decoded, expected_array); + assert_arrays_eq!(decoded, array); // 2 chunks: 1024 + 476 elements assert_eq!(encoded.values_idx_offsets().len(), 2); } @@ -301,14 +300,13 @@ mod test { fn test_two_full_chunks() { // Array that spans exactly 2 chunks (2048 elements) let values: Buffer = (0..2048).map(|i| (i / 100) as u32).collect(); - let array = values.clone().into_array(); + let array = values.into_array(); let encoded = RLEArray::encode(&array.to_primitive()).unwrap(); let decoded = encoded.to_primitive(); assert_eq!(encoded.len(), 2048); - let expected_array = PrimitiveArray::from_iter(expected); - assert_arrays_eq!(decoded, expected_array); + assert_arrays_eq!(decoded, array); assert_eq!(encoded.values_idx_offsets().len(), 2); }