You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "HippoBaro (via GitHub)" <gi...@apache.org> on 2026/04/28 23:08:58 UTC
[PR] test(parquet): replace `InMemoryArrayReader` with `PrimitiveArrayReader` [arrow-rs]
HippoBaro opened a new pull request, #9847:
URL: https://github.com/apache/arrow-rs/pull/9847
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax.
-->
- Contributes to #9731
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
`InMemoryArrayReader` couples a column's in-memory representation (an Arrow array) with its storage representation (def/rep levels) and assumes a 1:1 mapping between array elements and levels. This holds when list readers consume fully-padded child arrays — one element per level, nulls included.
Upcoming work pushes null filtering from `ListArrayReader` down into the child reader at the storage level, breaking that 1:1 assumption: the child returns fewer array elements than levels, and the mapping between them depends on the filtering logic itself. Keeping the mock would mean reimplementing that logic: testing filtered output against a second, hand-rolled filter.
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Replace `InMemoryArrayReader` with real `PrimitiveArrayReader` instances backed by in-memory Parquet pages. Tests now accept raw non-null values and levels (matching what Parquet actually stores) and exercise the production `RecordReader` path.
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
All tests passing.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
None.
--
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
Re: [PR] test(parquet): replace `InMemoryArrayReader` with `PrimitiveArrayReader` in tests [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #9847:
URL: https://github.com/apache/arrow-rs/pull/9847
--
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
Re: [PR] test(parquet): replace `InMemoryArrayReader` with `PrimitiveArrayReader` in tests [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9847:
URL: https://github.com/apache/arrow-rs/pull/9847#discussion_r3190285038
##########
parquet/src/arrow/array_reader/struct_array.rs:
##########
@@ -224,39 +224,27 @@ impl ArrayReader for StructArrayReader {
mod tests {
use super::*;
use crate::arrow::array_reader::ListArrayReader;
- use crate::arrow::array_reader::test_util::InMemoryArrayReader;
+ use crate::arrow::array_reader::test_util::make_int32_page_reader;
use arrow::buffer::Buffer;
use arrow::datatypes::Field;
use arrow_array::cast::AsArray;
- use arrow_array::{Array, Int32Array, ListArray};
+ use arrow_array::{Array, ListArray};
use arrow_schema::Fields;
#[test]
fn test_struct_array_reader() {
- let array_1 = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
- let array_reader_1 = InMemoryArrayReader::new(
- ArrowType::Int32,
- array_1.clone(),
- Some(vec![0, 1, 2, 3, 1]),
- Some(vec![0, 1, 1, 1, 1]),
- );
+ let array_reader_1 = make_int32_page_reader(&[4], &[0, 1, 2, 3, 1], &[0, 1, 1, 1, 1], 3, 1);
Review Comment:
- Filed a PR to track: https://github.com/apache/arrow-rs/issues/9921
##########
parquet/src/arrow/array_reader/struct_array.rs:
##########
@@ -224,39 +224,27 @@ impl ArrayReader for StructArrayReader {
mod tests {
use super::*;
use crate::arrow::array_reader::ListArrayReader;
- use crate::arrow::array_reader::test_util::InMemoryArrayReader;
+ use crate::arrow::array_reader::test_util::make_int32_page_reader;
use arrow::buffer::Buffer;
use arrow::datatypes::Field;
use arrow_array::cast::AsArray;
- use arrow_array::{Array, Int32Array, ListArray};
+ use arrow_array::{Array, ListArray};
use arrow_schema::Fields;
#[test]
fn test_struct_array_reader() {
- let array_1 = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
- let array_reader_1 = InMemoryArrayReader::new(
- ArrowType::Int32,
- array_1.clone(),
- Some(vec![0, 1, 2, 3, 1]),
- Some(vec![0, 1, 1, 1, 1]),
- );
+ let array_reader_1 = make_int32_page_reader(&[4], &[0, 1, 2, 3, 1], &[0, 1, 1, 1, 1], 3, 1);
Review Comment:
- Filed an issue to track: https://github.com/apache/arrow-rs/issues/9921
--
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
Re: [PR] test(parquet): replace `InMemoryArrayReader` with `PrimitiveArrayReader` in tests [arrow-rs]
Posted by "HippoBaro (via GitHub)" <gi...@apache.org>.
HippoBaro commented on code in PR #9847:
URL: https://github.com/apache/arrow-rs/pull/9847#discussion_r3174270952
##########
parquet/src/arrow/array_reader/struct_array.rs:
##########
@@ -224,39 +224,27 @@ impl ArrayReader for StructArrayReader {
mod tests {
use super::*;
use crate::arrow::array_reader::ListArrayReader;
- use crate::arrow::array_reader::test_util::InMemoryArrayReader;
+ use crate::arrow::array_reader::test_util::make_int32_page_reader;
use arrow::buffer::Buffer;
use arrow::datatypes::Field;
use arrow_array::cast::AsArray;
- use arrow_array::{Array, Int32Array, ListArray};
+ use arrow_array::{Array, ListArray};
use arrow_schema::Fields;
#[test]
fn test_struct_array_reader() {
- let array_1 = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
- let array_reader_1 = InMemoryArrayReader::new(
- ArrowType::Int32,
- array_1.clone(),
- Some(vec![0, 1, 2, 3, 1]),
- Some(vec![0, 1, 1, 1, 1]),
- );
+ let array_reader_1 = make_int32_page_reader(&[4], &[0, 1, 2, 3, 1], &[0, 1, 1, 1, 1], 3, 1);
Review Comment:
Oh that would be lovely
--
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
Re: [PR] test(parquet): replace `InMemoryArrayReader` with `PrimitiveArrayReader` in tests [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9847:
URL: https://github.com/apache/arrow-rs/pull/9847#discussion_r3173211519
##########
parquet/src/arrow/array_reader/test_util.rs:
##########
@@ -91,112 +88,51 @@ pub fn byte_array_all_encodings(
(pages, encoded_dictionary)
}
-/// Array reader for test.
-pub struct InMemoryArrayReader {
- data_type: ArrowType,
- array: ArrayRef,
- def_levels: Option<Vec<i16>>,
- rep_levels: Option<Vec<i16>>,
- last_idx: usize,
- cur_idx: usize,
- need_consume_records: usize,
-}
-
-impl InMemoryArrayReader {
- pub fn new(
- data_type: ArrowType,
- array: ArrayRef,
- def_levels: Option<Vec<i16>>,
- rep_levels: Option<Vec<i16>>,
- ) -> Self {
- assert!(
- def_levels
- .as_ref()
- .map(|d| d.len() == array.len())
- .unwrap_or(true)
- );
-
- assert!(
- rep_levels
- .as_ref()
- .map(|r| r.len() == array.len())
- .unwrap_or(true)
- );
-
- Self {
- data_type,
- array,
- def_levels,
- rep_levels,
- cur_idx: 0,
- last_idx: 0,
- need_consume_records: 0,
- }
- }
-}
-
-impl ArrayReader for InMemoryArrayReader {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
- fn get_data_type(&self) -> &ArrowType {
- &self.data_type
- }
-
- fn read_records(&mut self, batch_size: usize) -> Result<usize> {
- assert_ne!(batch_size, 0);
- // This replicates the logical normally performed by
- // RecordReader to delimit semantic records
- let read = match &self.rep_levels {
- Some(rep_levels) => {
- let rep_levels = &rep_levels[self.cur_idx..];
- let mut levels_read = 0;
- let mut records_read = 0;
- while levels_read < rep_levels.len() && records_read < batch_size {
- if rep_levels[levels_read] == 0 {
- records_read += 1; // Start of new record
- }
- levels_read += 1;
- }
-
- // Find end of current record
- while levels_read < rep_levels.len() && rep_levels[levels_read] != 0 {
- levels_read += 1
- }
- levels_read
- }
- None => batch_size.min(self.array.len() - self.cur_idx),
- };
- self.need_consume_records += read;
- Ok(read)
- }
-
- fn consume_batch(&mut self) -> Result<ArrayRef> {
- let batch_size = self.need_consume_records;
- assert_ne!(batch_size, 0);
- self.last_idx = self.cur_idx;
- self.cur_idx += batch_size;
- self.need_consume_records = 0;
- Ok(self.array.slice(self.last_idx, batch_size))
- }
+/// Build a real `PrimitiveArrayReader<Int32Type>` from raw non-null values
+/// and definition/repetition levels. This exercises the full production
+/// `RecordReader` code path (including selective padding when a parent
+/// `ListArrayReader` calls `enable_selective_padding`).
+///
+/// `values` must contain only the non-null values (entries where
+/// `def_levels[i] == max_def_level`), in order, as Parquet encodes them.
+pub fn make_int32_page_reader(
+ values: &[i32],
Review Comment:
I double checked that all callsites actually used `DataType::Int32` which makes sense to me
##########
parquet/src/arrow/array_reader/test_util.rs:
##########
@@ -91,112 +88,51 @@ pub fn byte_array_all_encodings(
(pages, encoded_dictionary)
}
-/// Array reader for test.
-pub struct InMemoryArrayReader {
- data_type: ArrowType,
- array: ArrayRef,
- def_levels: Option<Vec<i16>>,
- rep_levels: Option<Vec<i16>>,
- last_idx: usize,
- cur_idx: usize,
- need_consume_records: usize,
-}
-
-impl InMemoryArrayReader {
- pub fn new(
- data_type: ArrowType,
- array: ArrayRef,
- def_levels: Option<Vec<i16>>,
- rep_levels: Option<Vec<i16>>,
- ) -> Self {
- assert!(
- def_levels
- .as_ref()
- .map(|d| d.len() == array.len())
- .unwrap_or(true)
- );
-
- assert!(
- rep_levels
- .as_ref()
- .map(|r| r.len() == array.len())
- .unwrap_or(true)
- );
-
- Self {
- data_type,
- array,
- def_levels,
- rep_levels,
- cur_idx: 0,
- last_idx: 0,
- need_consume_records: 0,
- }
- }
-}
-
-impl ArrayReader for InMemoryArrayReader {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
- fn get_data_type(&self) -> &ArrowType {
- &self.data_type
- }
-
- fn read_records(&mut self, batch_size: usize) -> Result<usize> {
- assert_ne!(batch_size, 0);
- // This replicates the logical normally performed by
- // RecordReader to delimit semantic records
- let read = match &self.rep_levels {
- Some(rep_levels) => {
- let rep_levels = &rep_levels[self.cur_idx..];
- let mut levels_read = 0;
- let mut records_read = 0;
- while levels_read < rep_levels.len() && records_read < batch_size {
- if rep_levels[levels_read] == 0 {
- records_read += 1; // Start of new record
- }
- levels_read += 1;
- }
-
- // Find end of current record
- while levels_read < rep_levels.len() && rep_levels[levels_read] != 0 {
- levels_read += 1
- }
- levels_read
- }
- None => batch_size.min(self.array.len() - self.cur_idx),
- };
- self.need_consume_records += read;
- Ok(read)
- }
-
- fn consume_batch(&mut self) -> Result<ArrayRef> {
- let batch_size = self.need_consume_records;
- assert_ne!(batch_size, 0);
- self.last_idx = self.cur_idx;
- self.cur_idx += batch_size;
- self.need_consume_records = 0;
- Ok(self.array.slice(self.last_idx, batch_size))
- }
+/// Build a real `PrimitiveArrayReader<Int32Type>` from raw non-null values
+/// and definition/repetition levels. This exercises the full production
+/// `RecordReader` code path (including selective padding when a parent
+/// `ListArrayReader` calls `enable_selective_padding`).
+///
+/// `values` must contain only the non-null values (entries where
Review Comment:
👍
##########
parquet/src/arrow/array_reader/struct_array.rs:
##########
@@ -224,39 +224,27 @@ impl ArrayReader for StructArrayReader {
mod tests {
use super::*;
use crate::arrow::array_reader::ListArrayReader;
- use crate::arrow::array_reader::test_util::InMemoryArrayReader;
+ use crate::arrow::array_reader::test_util::make_int32_page_reader;
use arrow::buffer::Buffer;
use arrow::datatypes::Field;
use arrow_array::cast::AsArray;
- use arrow_array::{Array, Int32Array, ListArray};
+ use arrow_array::{Array, ListArray};
use arrow_schema::Fields;
#[test]
fn test_struct_array_reader() {
- let array_1 = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
- let array_reader_1 = InMemoryArrayReader::new(
- ArrowType::Int32,
- array_1.clone(),
- Some(vec![0, 1, 2, 3, 1]),
- Some(vec![0, 1, 1, 1, 1]),
- );
+ let array_reader_1 = make_int32_page_reader(&[4], &[0, 1, 2, 3, 1], &[0, 1, 1, 1, 1], 3, 1);
Review Comment:
As an API suggestion (maybe for another PR, not required):
I would personally find this much easier to understand if the fields were named so I didn't have to refer to `make_int32_page_reader` to figure out what`&[0, 1, 2, 3, 1]` and `&[0, 1, 1, 1, 1]` meant.
Perhaps we could do this with an builder in the test. Something like this perhaps:
```rust
let array_reader_1 = TestArrayReaderBuilder::new()
.with_non_null_i32_values(&[4]) // <-- this is especially non obvous if you are used to normal Arrow arrays
.with_def_levels(&[0, 1, 2, 3, 1])
.with_rep_levels(&[0, 1, 1, 1, 1])
.with_max_def_level(3)
.with_max_rep_level(1)
.build()
```
--
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
Re: [PR] test(parquet): replace `InMemoryArrayReader` with `PrimitiveArrayReader` in tests [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #9847:
URL: https://github.com/apache/arrow-rs/pull/9847#issuecomment-4381466333
Thanks again @HippoBaro
--
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