Skip to content

Commit

Permalink
fix variadic counting
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Mar 17, 2024
1 parent 4f0c80d commit 4c29007
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion arrow-ipc/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<_>, _>>()?;
Expand Down Expand Up @@ -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()
}
Expand Down
5 changes: 4 additions & 1 deletion arrow-ipc/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ impl IpcDataGenerator {
fn set_variadic_buffer_counts(counts: &mut Vec<i64>, 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::<StructArray>().unwrap();
Expand Down

0 comments on commit 4c29007

Please sign in to comment.