Abdallah-Afifi commented on code in PR #11539:
URL: https://github.com/apache/arrow-rs/pull/11539#discussion_r4710479397


##########
parquet/src/encodings/encoding/alp_encoder.rs:
##########
@@ -733,11 +746,38 @@ where
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::encodings::alp::ALP_DEFAULT_LOG_VECTOR_SIZE;
+
+    /// The spec-recommended size the encoder defaults to; most tests pin to 
it so
+    /// existing coverage keeps measuring the default path.
+    const DEFAULT_VECTOR_SIZE: usize = 1 << ALP_DEFAULT_LOG_VECTOR_SIZE;
     use crate::data_type::{DoubleType, FloatType};
     use crate::encodings::decoding::Decoder;
     use crate::encodings::decoding::alp_decoder::AlpDecoder;

Review Comment:
   Fixed.



##########
parquet/src/encodings/encoding/alp_encoder.rs:
##########
@@ -733,11 +746,38 @@ where
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::encodings::alp::ALP_DEFAULT_LOG_VECTOR_SIZE;
+
+    /// The spec-recommended size the encoder defaults to; most tests pin to 
it so
+    /// existing coverage keeps measuring the default path.
+    const DEFAULT_VECTOR_SIZE: usize = 1 << ALP_DEFAULT_LOG_VECTOR_SIZE;
     use crate::data_type::{DoubleType, FloatType};
     use crate::encodings::decoding::Decoder;
     use crate::encodings::decoding::alp_decoder::AlpDecoder;
 
     /// Encode `values` and read them back through the decoder.
+    /// Encode at `vector_size` and read back. The decoder takes the size from 
the
+    /// page header, so it needs no configuration of its own.
+    fn roundtrip_with_log_vector_size<T: DataType>(
+        values: &[T::T],
+        log_vector_size: u8,
+    ) -> Vec<T::T>
+    where
+        T::T: AlpFloat,
+        <T::T as AlpFloat>::Exact: Send,
+    {
+        let options = AlpEncoderOptions::try_new(log_vector_size).unwrap();
+        let mut encoder = AlpEncoder::<T>::new_with_options(options);
+        encoder.put(values).unwrap();
+        let page = encoder.flush_buffer().unwrap();
+
+        let mut decoder = AlpDecoder::<T>::new();
+        decoder.set_data(page, values.len()).unwrap();
+        let mut out = vec![T::T::default(); values.len()];
+        assert_eq!(decoder.get(&mut out).unwrap(), values.len());
+        out
+    }
+

Review Comment:
   Removed, and `roundtrip` has its doc line back.



##########
parquet/src/encodings/encoding/alp_encoder.rs:
##########
@@ -1125,4 +1167,55 @@ mod tests {
             "a leading empty page must not affect encoding of the first 
nonempty page"
         );
     }
+    /// Every `log_vector_size` the format permits must round-trip, including 
the
+    /// 3 and 15 bounds, and across both the buffered first page and the 
streaming path.
+    #[test]
+    fn test_roundtrip_all_vector_sizes() {
+        let values: Vec<f64> = (0..5000).map(|i| (i as f64) * 0.01 - 
7.5).collect();
+        for log_vector_size in 3u8..=15 {
+            let out = roundtrip_with_log_vector_size::<DoubleType>(&values, 
log_vector_size);
+            assert_bits_eq(&out, &values);
+        }
+    }
+
+    /// A non-default vector size must survive the streaming path, where the 
size
+    /// governs the carry across `put` boundaries.
+    #[test]
+    fn test_streaming_with_non_default_vector_size() {
+        let page1: Vec<f64> = (0..3000).map(|i| (i as f64) * 0.01).collect();
+        let page2: Vec<f64> = (0..3000).map(|i| (i as f64) * 0.03 - 
7.0).collect();
+        let options = AlpEncoderOptions::try_new(13).unwrap();
+        let vector_size = options.vector_size();
+
+        let mut encoder = AlpEncoder::<DoubleType>::new_with_options(options);
+        encoder.put(&page1).unwrap();
+        let _ = encoder.flush_buffer().unwrap();
+
+        // Feed page 2 in chunks that straddle vector boundaries.
+        for chunk in page2.chunks(997) {
+            encoder.put(chunk).unwrap();
+        }
+        let streamed = encoder.flush_buffer().unwrap();
+
+        // Same values, same preset, encoded in one pass.
+        let preset = build_preset(&page1, vector_size);
+        let mut scratch = Scratch::<f64>::new();
+        let reference = encode_page(&page2, &preset, vector_size, &mut 
scratch).unwrap();
+        assert_eq!(streamed.as_ref(), reference.as_slice());
+    }
+
+    /// The configured size must reach the page header, which is what lets the
+    /// decoder read the page back without being told.
+    #[test]
+    fn test_vector_size_recorded_in_page_header() {
+        let values: Vec<f64> = (0..2000).map(|i| (i as f64) * 0.01).collect();
+        for log_vector_size in [3u8, 10, 13, 15] {
+            let options = AlpEncoderOptions::try_new(log_vector_size).unwrap();
+            let mut encoder = 
AlpEncoder::<DoubleType>::new_with_options(options);
+            encoder.put(&values).unwrap();
+            let page = encoder.flush_buffer().unwrap();
+            // log_vector_size is byte 2 of the ALP header.
+            assert_eq!(page[2], log_vector_size);
+        }
+    }

Review Comment:
   Agreed, removed.



##########
parquet/src/encodings/encoding/alp_encoder.rs:
##########
@@ -616,6 +618,8 @@ where
     scratch: Scratch<T::T>,
     /// The page built incrementally, used for every page after the first.
     streaming: StreamingPage<T::T>,
+    /// Values per vector, from the column's `log_vector_size`.
+    vector_size: usize,

Review Comment:
   Done. `AlpEncoder` reads `self.streaming.vector_size` now, and the 
`vector_size: _` in `put` is gone.



##########
parquet/src/encodings/encoding/alp_encoder.rs:
##########
@@ -1125,4 +1167,55 @@ mod tests {
             "a leading empty page must not affect encoding of the first 
nonempty page"
         );
     }
+    /// Every `log_vector_size` the format permits must round-trip, including 
the
+    /// 3 and 15 bounds, and across both the buffered first page and the 
streaming path.
+    #[test]
+    fn test_roundtrip_all_vector_sizes() {
+        let values: Vec<f64> = (0..5000).map(|i| (i as f64) * 0.01 - 
7.5).collect();
+        for log_vector_size in 3u8..=15 {
+            let out = roundtrip_with_log_vector_size::<DoubleType>(&values, 
log_vector_size);
+            assert_bits_eq(&out, &values);
+        }
+    }

Review Comment:
   Taken as suggested. I checked it by injecting a hardcoded 1024 in three 
places. Before this change, `chunks_exact(1024)` passed the whole suite. Now it 
fails this test, and so do a hardcoded carry split and a hardcoded size in the 
`finish` header.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to