From b74b2191c5465215663d97b4be52df7a023146f1 Mon Sep 17 00:00:00 2001 From: Andrew Duffy Date: Wed, 5 Jun 2024 18:06:45 +0100 Subject: [PATCH] cleanup ,test --- vortex-array/src/array/struct/mod.rs | 4 -- vortex-array/src/compute/as_contiguous.rs | 11 +--- vortex-datetime-parts/src/compute.rs | 68 +++++++++++++++++++++++ vortex-dict/src/compress.rs | 2 - 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/vortex-array/src/array/struct/mod.rs b/vortex-array/src/array/struct/mod.rs index e61a96e001..91d4c6c10b 100644 --- a/vortex-array/src/array/struct/mod.rs +++ b/vortex-array/src/array/struct/mod.rs @@ -70,10 +70,6 @@ impl StructArray { } if fields.iter().any(|a| a.with_dyn(|a| a.len()) != length) { - println!( - "FIELD LENGTHS: {:?}", - fields.iter().map(|field| field.len()).collect::>() - ); vortex_bail!("Expected all struct fields to have length {}", length); } diff --git a/vortex-array/src/compute/as_contiguous.rs b/vortex-array/src/compute/as_contiguous.rs index 80572d68a8..aa41cffbf9 100644 --- a/vortex-array/src/compute/as_contiguous.rs +++ b/vortex-array/src/compute/as_contiguous.rs @@ -3,12 +3,12 @@ use vortex_error::{vortex_bail, vortex_err, VortexResult}; use crate::{Array, ArrayDType}; -/// Trait for typed array variants which support the process of unfurling to somewhere else. +/// Trait that exposes an operation for repacking (and possibly decompressing) an [Array] into +/// a new Array that occupies a contiguous memory range. pub trait AsContiguousFn { fn as_contiguous(&self, arrays: &[Array]) -> VortexResult; } -/// Macro that #[macro_export] macro_rules! impl_default_as_contiguous_fn { ($typ:ty) => { @@ -45,13 +45,6 @@ pub fn as_contiguous(arrays: &[Array]) -> VortexResult { vortex_bail!(ComputeError: "No arrays to concatenate"); } if !arrays.iter().map(|chunk| chunk.encoding().id()).all_equal() { - println!( - "ENCODINGS: {:?}", - arrays - .iter() - .map(|chunk| chunk.encoding().id()) - .collect_vec() - ); vortex_bail!(ComputeError: "Chunks have differing encodings"); } if !arrays.iter().map(|chunk| chunk.dtype()).all_equal() { diff --git a/vortex-datetime-parts/src/compute.rs b/vortex-datetime-parts/src/compute.rs index 9090f29cd4..68318397f2 100644 --- a/vortex-datetime-parts/src/compute.rs +++ b/vortex-datetime-parts/src/compute.rs @@ -184,3 +184,71 @@ impl AsContiguousFn for DateTimePartsArray { as_contiguous(chunks.as_slice()) } } + +#[cfg(test)] +mod test { + use vortex::array::datetime::{LocalDateTimeArray, TimeUnit}; + use vortex::array::primitive::PrimitiveArray; + use vortex::compute::scalar_at::scalar_at; + use vortex::validity::Validity; + use vortex::IntoArray; + use vortex_dtype::{DType, ExtDType, ExtID, Nullability}; + + use crate::compute::decode_to_localdatetime; + use crate::DateTimePartsArray; + + #[test] + fn test_decode_to_localdatetime() { + let nanos = TimeUnit::Ns; + + let days = PrimitiveArray::from_vec(vec![2i64, 3], Validity::NonNullable).into_array(); + let seconds = PrimitiveArray::from_vec(vec![2i64, 3], Validity::NonNullable).into_array(); + let subsecond = PrimitiveArray::from_vec(vec![2i64, 3], Validity::NonNullable).into_array(); + + let date_times = DateTimePartsArray::try_new( + DType::Extension( + ExtDType::new( + ExtID::from(LocalDateTimeArray::ID), + Some(nanos.metadata().clone()), + ), + Nullability::NonNullable, + ), + days, + seconds, + subsecond, + ) + .unwrap(); + + let local = decode_to_localdatetime(&date_times.into_array()).unwrap(); + + let elem0: i64 = scalar_at(&local.timestamps(), 0) + .unwrap() + .value() + .as_pvalue() + .unwrap() + .unwrap() + .try_into() + .unwrap(); + let elem1: i64 = scalar_at(&local.timestamps(), 1) + .unwrap() + .value() + .as_pvalue() + .unwrap() + .unwrap() + .try_into() + .unwrap(); + + assert_eq!( + elem0, + vec![(2i64 * 86_400 * 1_000_000_000), 2i64 * 1_000_000_000, 2i64,] + .into_iter() + .sum(), + ); + assert_eq!( + elem1, + vec![(3i64 * 86_400 * 1_000_000_000), 3i64 * 1_000_000_000, 3i64,] + .into_iter() + .sum(), + ); + } +} diff --git a/vortex-dict/src/compress.rs b/vortex-dict/src/compress.rs index 662f274a4f..f57f6ca649 100644 --- a/vortex-dict/src/compress.rs +++ b/vortex-dict/src/compress.rs @@ -149,8 +149,6 @@ pub fn dict_encode_typed_primitive( Validity::NonNullable }; - println!("values_validity: {:?}", values_validity); - ( PrimitiveArray::from(codes), PrimitiveArray::from_vec(values, values_validity),