Skip to content

Commit

Permalink
Fix incorrect null_count in generate_unions_case integration test (#…
Browse files Browse the repository at this point in the history
…1713)

* Fix incorrect null_count

* Add check at reader too
  • Loading branch information
viirya authored May 21, 2022
1 parent 8855d22 commit 7b164a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 11 additions & 2 deletions arrow/src/ipc/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,18 @@ fn create_array(
Arc::new(array)
}
Null => {
let length = nodes[node_index].length() as usize;
let length = nodes[node_index].length();
let null_count = nodes[node_index].null_count();

if length != null_count {
return Err(ArrowError::IoError(format!(
"Field {} of NullArray has unequal null_count {} and len {}",
field, null_count, length
)));
}

let data = ArrayData::builder(data_type.clone())
.len(length)
.len(length as usize)
.offset(0)
.build()
.unwrap();
Expand Down
8 changes: 7 additions & 1 deletion arrow/src/ipc/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,13 @@ fn write_array_data(
null_count: usize,
) -> i64 {
let mut offset = offset;
nodes.push(ipc::FieldNode::new(num_rows as i64, null_count as i64));
if !matches!(array_data.data_type(), DataType::Null) {
nodes.push(ipc::FieldNode::new(num_rows as i64, null_count as i64));
} else {
// NullArray's null_count equals to len, but the `null_count` passed in is from ArrayData
// where null_count is always 0.
nodes.push(ipc::FieldNode::new(num_rows as i64, num_rows as i64));
}
// NullArray does not have any buffers, thus the null buffer is not generated
// UnionArray does not have a validity buffer
if !matches!(
Expand Down

0 comments on commit 7b164a0

Please sign in to comment.