Skip to content

Commit

Permalink
Merge 7f03b63 into 7d00e3c
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya authored May 1, 2022
2 parents 7d00e3c + 7f03b63 commit 3315175
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions arrow/src/array/array_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,24 @@ impl Array for UnionArray {
fn data(&self) -> &ArrayData {
&self.data
}

/// Union types always return non null as there is no validity buffer.
/// To check validity correctly you must check the underlying vector.
fn is_null(&self, _index: usize) -> bool {
false
}

/// Union types always return non null as there is no validity buffer.
/// To check validity correctly you must check the underlying vector.
fn is_valid(&self, _index: usize) -> bool {
true
}

/// Union types always return 0 null count as there is no validity buffer.
/// To get null count correctly you must check the underlying vector.
fn null_count(&self) -> usize {
0
}
}

impl fmt::Debug for UnionArray {
Expand Down Expand Up @@ -877,6 +895,38 @@ mod tests {
}
}

fn test_union_validity(union_array: &UnionArray) {
assert_eq!(union_array.null_count(), 0);

for i in 0..union_array.len() {
assert!(!union_array.is_null(i));
assert!(union_array.is_valid(i));
}
}

#[test]
fn test_union_array_validaty() {
let mut builder = UnionBuilder::new_sparse(5);
builder.append::<Int32Type>("a", 1).unwrap();
builder.append_null::<Int32Type>("a").unwrap();
builder.append::<Float64Type>("c", 3.0).unwrap();
builder.append_null::<Float64Type>("c").unwrap();
builder.append::<Int32Type>("a", 4).unwrap();
let union = builder.build().unwrap();

test_union_validity(&union);

let mut builder = UnionBuilder::new_dense(5);
builder.append::<Int32Type>("a", 1).unwrap();
builder.append_null::<Int32Type>("a").unwrap();
builder.append::<Float64Type>("c", 3.0).unwrap();
builder.append_null::<Float64Type>("c").unwrap();
builder.append::<Int32Type>("a", 4).unwrap();
let union = builder.build().unwrap();

test_union_validity(&union);
}

#[test]
fn test_type_check() {
let mut builder = UnionBuilder::new_sparse(2);
Expand Down

0 comments on commit 3315175

Please sign in to comment.