From 4c29007f111a6a147f532c408fbb84761e722dd7 Mon Sep 17 00:00:00 2001 From: Xiangpeng Hao Date: Sun, 17 Mar 2024 22:48:03 +0000 Subject: [PATCH] fix variadic counting --- arrow-ipc/src/reader.rs | 3 ++- arrow-ipc/src/writer.rs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arrow-ipc/src/reader.rs b/arrow-ipc/src/reader.rs index c4d9703847e5..d9d474d5d3f4 100644 --- a/arrow-ipc/src/reader.rs +++ b/arrow-ipc/src/reader.rs @@ -87,7 +87,7 @@ fn create_array( let count = variadic_counts .pop_front() .expect("Incorrect variadic count!"); - let count = count + 1; // add the null buffer. + let count = count + 2; // view and null buffer. let buffers = (0..count) .map(|_| reader.next_buffer()) .collect::, _>>()?; @@ -360,6 +360,7 @@ impl<'a> ArrayReader<'a> { let count = variadic_count .pop_front() .expect("Incorrect variadic count!"); + let count = count + 2; // view and null buffer. for _i in 0..count { self.skip_buffer() } diff --git a/arrow-ipc/src/writer.rs b/arrow-ipc/src/writer.rs index c5632f0ddc34..46dd17c3e805 100644 --- a/arrow-ipc/src/writer.rs +++ b/arrow-ipc/src/writer.rs @@ -567,7 +567,10 @@ impl IpcDataGenerator { fn set_variadic_buffer_counts(counts: &mut Vec, array: &dyn Array) { match array.data_type() { DataType::BinaryView | DataType::Utf8View => { - counts.push(array.to_data().buffers().len() as i64); + // The spec is not clear on whether the view/null buffer should be included in the variadic buffer count. + // But from C++ impl https://github.com/apache/arrow/blob/b448b33808f2dd42866195fa4bb44198e2fc26b9/cpp/src/arrow/ipc/writer.cc#L477 + // we know they are not included. + counts.push(array.to_data().buffers().len() as i64 - 1); } DataType::Struct(_) => { let array = array.as_any().downcast_ref::().unwrap();