diff --git a/encodings/fastlanes/src/bitpacking/compute/cast.rs b/encodings/fastlanes/src/bitpacking/compute/cast.rs index 3304e085582..eb189edb50f 100644 --- a/encodings/fastlanes/src/bitpacking/compute/cast.rs +++ b/encodings/fastlanes/src/bitpacking/compute/cast.rs @@ -79,7 +79,7 @@ mod tests { let decoded = casted.to_primitive(); assert_arrays_eq!( - decoded, + decoded.as_ref(), PrimitiveArray::from_iter([10u32, 20, 30, 40, 50, 60]) ); } diff --git a/encodings/fastlanes/src/rle/compress.rs b/encodings/fastlanes/src/rle/compress.rs index e0e0e622690..3fe5f3f5e85 100644 --- a/encodings/fastlanes/src/rle/compress.rs +++ b/encodings/fastlanes/src/rle/compress.rs @@ -285,15 +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 expected: Vec = (0..1500).map(|i| (i / 100) as u32).collect(); 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); } @@ -302,15 +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 expected: Vec = (0..2048).map(|i| (i / 100) as u32).collect(); 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); } 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 86a3d810692..656a8a2f22a 100644 --- a/vortex-layout/src/layouts/chunked/reader.rs +++ b/vortex-layout/src/layouts/chunked/reader.rs @@ -268,7 +268,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}; @@ -325,11 +325,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 efba21d57fb..502a67b0dce 100644 --- a/vortex-layout/src/layouts/flat/reader.rs +++ b/vortex-layout/src/layouts/flat/reader.rs @@ -207,7 +207,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; @@ -318,10 +318,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 fa1f1787d9e..fff725b7a0f 100644 --- a/vortex-layout/src/layouts/zoned/reader.rs +++ b/vortex-layout/src/layouts/zoned/reader.rs @@ -351,7 +351,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; @@ -408,11 +408,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()); }) }