This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-12267-2a6c9effccde7d9c58c801d2b8ed39a86eb1bc6e in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
commit 7dd9f12d7410dfa9b55d97d650eb1d9f16cc5ad6 Author: mola <[email protected]> AuthorDate: Mon Nov 16 14:15:08 2026 +0000 fix(arrow-ipc): do not write a validity bitmap for RunEndEncoded in V4 (#12267) - Closes #12248 # Rationale for this change A `RunEndEncoded` array written with `MetadataVersion::V4` does not read back. `has_validity_bitmap` in `arrow-ipc/src/writer.rs` excluded only `Null` in the V4 branch, so the writer emitted a validity buffer for RunEndEncoded arrays (a 0-length one when `null_count` is 0). The reader never consumes a validity buffer for RunEndEncoded in any metadata version, so it takes that buffer as the run-ends buffer and every later buffer is off by one. The reader fails with `InvalidArgumentError("Need at least 8 bytes in buffers[0] in array of type Int32, but got 0")`. # What changes are included in this PR? - `has_validity_bitmap` now also excludes `DataType::RunEndEncoded(_, _)` in the V4 branch, matching the V5 branch, the reader, and the function's own doc comment (which already stated RunEndEncoded has no validity bitmap). The flatbuffers spec lists only Union's validity bitmap as a V4 to V5 difference, so no V4 reader expects one. - One regression test `test_roundtrip_stream_run_array_v4` in `arrow-ipc/src/reader.rs`, following the issue reproducer exactly (Int32 run-ends `[2, 5]`, values `[10, 20]`, written with `MetadataVersion::V4`, read back and asserted equal). # Are these changes tested? Yes. The new test fails on current main with the exact error from the issue and passes with the fix. The full `arrow-ipc` suite (167 tests) and the downstream `arrow-array` and `arrow-data` suites (1068 tests) pass, and `cargo fmt` and `cargo clippy` are clean. <img width="1278" height="133" alt="arrow-rs-12248-verify-before-fix" src="https://github.com/user-attachments/assets/aa9927c1-74d4-42bb-b570-2daf67232fd0" /> <img width="899" height="196" alt="arrow-rs-12248-verify-after-fix" src="https://github.com/user-attachments/assets/000cdcf3-87e0-4d0c-af16-f5bf6356f8d3" /> # Are there any significant user-facing changes? Behavior fix only: RunEndEncoded arrays written with MetadataVersion::V4 now read back correctly. No public API change. # AI usage disclosure AI assistance was used to implement the fix and tests, following the approach described in #12248; the changes were verified with the crate's test suite, clippy and fmt. --- arrow-ipc/src/reader.rs | 33 +++++++++++++++++++++++++++++++++ arrow-ipc/src/writer.rs | 7 +++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/arrow-ipc/src/reader.rs b/arrow-ipc/src/reader.rs index 8564103dfc..a2ec722f04 100644 --- a/arrow-ipc/src/reader.rs +++ b/arrow-ipc/src/reader.rs @@ -3166,6 +3166,39 @@ mod tests { assert_eq!(run_array_1_unsliced, output_batch.column(0).into_data()); } + // Regression test for https://github.com/apache/arrow-rs/issues/12248: + // a RunEndEncoded array written with MetadataVersion::V4 did not read + // back, because the writer emitted a validity buffer for it while the + // reader never consumes one, shifting every later buffer by one. + #[test] + fn test_roundtrip_stream_run_array_v4() { + use crate::MetadataVersion; + use crate::writer::{IpcWriteOptions, StreamWriter}; + + let run_ends = Int32Array::from(vec![2, 5]); + let values = Int32Array::from(vec![10, 20]); + let array = RunArray::<Int32Type>::try_new(&run_ends, &values).unwrap(); + let schema = Arc::new(Schema::new(vec![Field::new( + "a", + array.data_type().clone(), + false, + )])); + let batch = RecordBatch::try_new(schema.clone(), vec![Arc::new(array)]).unwrap(); + + let mut buf = Vec::new(); + { + let options = IpcWriteOptions::try_new(8, false, MetadataVersion::V4).unwrap(); + let mut writer = + StreamWriter::try_new_with_options(&mut buf, &schema, options).unwrap(); + writer.write(&batch).unwrap(); + writer.finish().unwrap(); + } + + let mut reader = StreamReader::try_new(buf.as_slice(), None).unwrap(); + let read = reader.next().unwrap().unwrap(); + assert_eq!(read, batch); + } + #[test] fn test_roundtrip_stream_nested_dict() { let xs = vec!["AA", "BB", "AA", "CC", "BB"]; diff --git a/arrow-ipc/src/writer.rs b/arrow-ipc/src/writer.rs index 33bf06cb61..755ac82cdd 100644 --- a/arrow-ipc/src/writer.rs +++ b/arrow-ipc/src/writer.rs @@ -2255,12 +2255,11 @@ pub fn write_message<W: Write>( writer.write_encoded_data(encoded, write_options) } -/// In V4, null types have no validity bitmap -/// In V5 and later, null and union types have no validity bitmap -/// Run end encoded type has no validity bitmap. +/// In V4, null and run end encoded types have no validity bitmap +/// In V5 and later, null, union and run end encoded types have no validity bitmap fn has_validity_bitmap(data_type: &DataType, write_options: &IpcWriteOptions) -> bool { if write_options.metadata_version < crate::MetadataVersion::V5 { - !matches!(data_type, DataType::Null) + !matches!(data_type, DataType::Null | DataType::RunEndEncoded(_, _)) } else { !matches!( data_type,
