This is an automated email from the ASF dual-hosted git repository.
viirya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 7b164a07b Fix incorrect null_count in `generate_unions_case`
integration test (#1713)
7b164a07b is described below
commit 7b164a07b43bc579bb5259fe0f95bf4332661922
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Sat May 21 15:13:58 2022 -0700
Fix incorrect null_count in `generate_unions_case` integration test (#1713)
* Fix incorrect null_count
* Add check at reader too
---
arrow/src/ipc/reader.rs | 13 +++++++++++--
arrow/src/ipc/writer.rs | 8 +++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/arrow/src/ipc/reader.rs b/arrow/src/ipc/reader.rs
index 662b384c4..2a6619ec8 100644
--- a/arrow/src/ipc/reader.rs
+++ b/arrow/src/ipc/reader.rs
@@ -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();
diff --git a/arrow/src/ipc/writer.rs b/arrow/src/ipc/writer.rs
index f61d4ce4c..ffeeadc9d 100644
--- a/arrow/src/ipc/writer.rs
+++ b/arrow/src/ipc/writer.rs
@@ -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!(