Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions arrow-ipc/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
7 changes: 3 additions & 4 deletions arrow-ipc/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading