You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/15 16:09:00 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2076: Support skip_values in ByteArrayColumnValueDecoder

tustvold commented on code in PR #2076:
URL: https://github.com/apache/arrow-rs/pull/2076#discussion_r922305417


##########
parquet/src/arrow/array_reader/byte_array.rs:
##########
@@ -589,6 +680,38 @@ impl ByteArrayDecoderDictionary {
         }
         Ok(values_read)
     }
+
+    fn skip<I: OffsetSizeTrait + ScalarValue>(
+        &mut self,
+        dict: &OffsetBuffer<I>,
+        to_skip: usize,
+    ) -> Result<usize> {
+        let to_skip = to_skip.min(self.max_remaining_values);
+        // All data must be NULL
+        if dict.is_empty() {
+            return Ok(0);
+        }
+
+        let mut values_skip = 0;
+        while values_skip < to_skip {
+            if self.index_offset == self.index_buf_len {
+                let read = self.decoder.get_batch(self.index_buf.as_mut())?;

Review Comment:
   Possibly something for a follow up PR, but it would be nice if we could avoid decoding values only to dump them on the floor



##########
parquet/src/arrow/array_reader/byte_array.rs:
##########
@@ -653,6 +776,57 @@ mod tests {
         }
     }
 
+    #[test]
+    fn test_byte_array_decoder_skip() {
+        let (pages, encoded_dictionary) =
+            byte_array_all_encodings(vec!["hello", "world", "a", "b"]);
+
+        let column_desc = utf8_column();
+        let mut decoder = ByteArrayColumnValueDecoder::new(&column_desc);
+
+        decoder
+            .set_dict(encoded_dictionary, 4, Encoding::RLE_DICTIONARY, false)
+            .unwrap();
+
+        for (encoding, page) in pages {
+            let mut output = OffsetBuffer::<i32>::default();
+            decoder.set_data(encoding, page, 4, Some(4)).unwrap();
+
+            assert_eq!(decoder.read(&mut output, 0..1).unwrap(), 1);
+
+            assert_eq!(output.values.as_slice(), "hello".as_bytes());
+            assert_eq!(output.offsets.as_slice(), &[0, 5]);
+
+            assert_eq!(decoder.skip_values(1).unwrap(), 1);
+            assert_eq!(decoder.skip_values(1).unwrap(), 1);
+
+            assert_eq!(decoder.read(&mut output, 0..1).unwrap(), 1);

Review Comment:
   ```suggestion
               assert_eq!(decoder.read(&mut output, 1..2).unwrap(), 1);
   ```
   
   The decoder doesn't actually care, as it keeps track of the number of read values, but this is technically more correct



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org