krtab opened a new issue, #12451:
URL: https://github.com/apache/arrow-rs/issues/12451
### Describe the bug
The `read_from_row_group` generated by `#[derive(ParquetRecordReader)]` only
gives correct results when the target `Vec` is empty. If the `Vec` already
holds records, the first `num_records` existing records are overwritten. The
new records are added at the end with their `Default` values. No error is
returned.
The generated code adds `num_records` default records to the end of `self`
with `self.extend(...)`. Each column then writes into `records[..num_records]`,
which is the start of the `Vec`, not the records that were just added.
### To Reproduce
```rust
use parquet::file::reader::FileReader;
use parquet::file::serialized_reader::SerializedFileReader;
use parquet::file::writer::SerializedFileWriter;
use parquet::record::{RecordReader, RecordWriter};
use parquet_derive::{ParquetRecordReader, ParquetRecordWriter};
#[derive(ParquetRecordWriter, ParquetRecordReader, Debug)]
struct Plain {
id: i32,
}
fn file_with(ids: &[i32]) -> bytes::Bytes {
let rows: Vec<Plain> = ids.iter().map(|&id| Plain { id }).collect();
let mut buf = Vec::new();
let schema = rows.as_slice().schema().unwrap();
let mut writer = SerializedFileWriter::new(&mut buf, schema,
Default::default()).unwrap();
let mut row_group = writer.next_row_group().unwrap();
rows.as_slice().write_to_row_group(&mut row_group).unwrap();
row_group.close().unwrap();
writer.close().unwrap();
buf.into()
}
fn main() {
let mut out: Vec<Plain> = Vec::new();
for ids in [[1, 2], [3, 4]] {
let reader = SerializedFileReader::new(file_with(&ids)).unwrap();
out.read_from_row_group(&mut *reader.get_row_group(0).unwrap(), 2)
.unwrap();
println!("{out:?}");
}
}
```
Output:
```
[Plain { id: 1 }, Plain { id: 2 }]
[Plain { id: 3 }, Plain { id: 4 }, Plain { id: 0 }, Plain { id: 0 }]
### Expected behavior
```text
[Plain { id: 1 }, Plain { id: 2 }]
[Plain { id: 1 }, Plain { id: 2 }, Plain { id: 3 }, Plain { id: 4 }]
```
### Additional context
_No response_
### Willingness to contribute
I plan to contribute a fix for this bug independently
--
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]