This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 584de0da5d Fix parquet derived reader overwriting existing records
(#12452)
584de0da5d is described below
commit 584de0da5d8cc79280f91c0873ef70ecc00ed2e5
Author: Arthur Carcano <[email protected]>
AuthorDate: Wed Nov 25 02:49:49 2026 +0000
Fix parquet derived reader overwriting existing records (#12452)
The derived read_from_row_group appends num_records placeholders to the
Vec, but then filled the first num_records elements of the Vec. When the
Vec was not empty, existing records were overwritten and the new ones
were left at their default values.
# Which issue does this PR close?
<!--
It is not necessary to raise an issue, but it is encouraged if it is a
non-trivial
enhancement/bug.
If this PR relates to an existing issue, but does not fully resolve it,
please change
the wording below from "Closes #NNN" to "Relates to #NNN" or "Part of
#NNN" to avoid
false closing an issue.
-->
- Closes #12451
# Are these changes tested?
A unit test is included. It fails without the fix and passes with it.
# Are there any significant user-facing changes?
The behavior is changed to match the one described in the doc and
intended.
# AI usage disclosure
Claude identified the issue when working on something else. It wrote the
fix and test, which I entirely reviewed.
---
parquet_derive/src/lib.rs | 3 ++-
parquet_derive_test/src/lib.rs | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/parquet_derive/src/lib.rs b/parquet_derive/src/lib.rs
index 3f4c9ab221..615fe0b1fb 100644
--- a/parquet_derive/src/lib.rs
+++ b/parquet_derive/src/lib.rs
@@ -262,6 +262,7 @@ pub fn parquet_record_reader(input:
proc_macro::TokenStream) -> proc_macro::Toke
.enumerate()
.map(|(idx,col)| (col.name().to_string(),idx))
.collect();
+ let initial_len = self.len();
self.extend(std::iter::repeat_with(|| {
#derived_for {
#(
@@ -270,7 +271,7 @@ pub fn parquet_record_reader(input:
proc_macro::TokenStream) -> proc_macro::Toke
}
}).take(num_records));
- let records = self; // Used by all the reader snippets to be more clear
+ let records = &mut self[initial_len..]; // Used by all the reader
snippets to be more clear
#(
{
diff --git a/parquet_derive_test/src/lib.rs b/parquet_derive_test/src/lib.rs
index 1b4a663c12..0382e36e0a 100644
--- a/parquet_derive_test/src/lib.rs
+++ b/parquet_derive_test/src/lib.rs
@@ -398,6 +398,34 @@ mod tests {
assert_eq!(drs, out);
}
+ #[test]
+ fn test_parquet_derive_read_into_non_empty_vec() {
+ #[derive(PartialEq, ParquetRecordWriter, ParquetRecordReader, Debug)]
+ struct ARecord {
+ id: i32,
+ }
+
+ let file =
get_temp_file("test_parquet_derive_read_into_non_empty_vec", &[]);
+ let drs = [ARecord { id: 1 }];
+
+ let schema = drs.as_slice().schema().unwrap();
+ let mut writer =
+ SerializedFileWriter::new(file.try_clone().unwrap(), schema,
Default::default())
+ .unwrap();
+ let mut row_group = writer.next_row_group().unwrap();
+ drs.as_slice().write_to_row_group(&mut row_group).unwrap();
+ row_group.close().unwrap();
+ writer.close().unwrap();
+
+ use parquet::file::{reader::FileReader,
serialized_reader::SerializedFileReader};
+ let reader = SerializedFileReader::new(file).unwrap();
+ let mut out = vec![ARecord { id: 7 }];
+ out.read_from_row_group(&mut *reader.get_row_group(0).unwrap(), 1)
+ .unwrap();
+
+ assert_eq!(out, [ARecord { id: 7 }, ARecord { id: 1 }]);
+ }
+
#[test]
fn test_aliased_result() {
// Issue 7547, Where aliasing the `Result` led to