-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement UnionArray logical_nulls #6303
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8bfb4f2
fix: implement UnionArray logical_nulls
gstvg 442e6f9
fix: allow false positive clippy warning
gstvg 9472786
fix: replace unstable functions
gstvg 9a921ff
improve docs, perf, validate sparse, revert msrv
gstvg 3a61305
Merge branch 'master' of https://github.com/apache/arrow-rs into unio…
gstvg 251ef82
simplify benches
gstvg e35aaa0
fine tune fast path threshold
gstvg 6100d7a
update docs
gstvg 49e78e2
fix fast path check, improve perf and docs
gstvg 5b965bf
Merge branch 'master' of https://github.com/apache/arrow-rs into unio…
gstvg 291691c
fix: remove rust 1.65 code
gstvg 3fd0b38
simplify mask_sparse_
gstvg 0b9a443
Merge branch 'master' into union_logical_nulls
gstvg b51bc86
apply suggestions from review
gstvg 74a3b20
Merge branch 'union_logical_nulls' of https://github.com/gstvg/arrow-…
gstvg f824ed3
Update arrow-array/src/array/union_array.rs
gstvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::{ | ||
iter::{repeat, repeat_with}, | ||
sync::Arc, | ||
}; | ||
|
||
use arrow_array::{Array, ArrayRef, Int32Array, UnionArray}; | ||
use arrow_buffer::{NullBuffer, ScalarBuffer}; | ||
use arrow_schema::{DataType, Field, UnionFields}; | ||
use criterion::*; | ||
use rand::{thread_rng, Rng}; | ||
|
||
fn array_with_nulls() -> ArrayRef { | ||
let mut rng = thread_rng(); | ||
|
||
let values = ScalarBuffer::from_iter(repeat_with(|| rng.gen()).take(4096)); | ||
|
||
// nulls with at least one null and one valid | ||
let nulls: NullBuffer = [true, false] | ||
.into_iter() | ||
.chain(repeat_with(|| rng.gen())) | ||
.take(4096) | ||
.collect(); | ||
|
||
Arc::new(Int32Array::new(values.clone(), Some(nulls))) | ||
} | ||
|
||
fn array_without_nulls() -> ArrayRef { | ||
let mut rng = thread_rng(); | ||
|
||
let values = ScalarBuffer::from_iter(repeat_with(|| rng.gen()).take(4096)); | ||
|
||
Arc::new(Int32Array::new(values.clone(), None)) | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
for with_nulls in 1..12 { | ||
for without_nulls in [0, 1, 10] { | ||
c.bench_function( | ||
&format!("union logical nulls 4096 {with_nulls} children with nulls, {without_nulls} without nulls"), | ||
|b| { | ||
let type_ids = 0..with_nulls+without_nulls; | ||
|
||
let fields = UnionFields::new( | ||
type_ids.clone(), | ||
type_ids.clone().map(|i| Field::new(format!("f{i}"), DataType::Int32, true)), | ||
); | ||
|
||
let array = UnionArray::try_new( | ||
fields, | ||
type_ids.cycle().take(4096).collect(), | ||
None, | ||
repeat(array_with_nulls()) | ||
.take(with_nulls as usize) | ||
.chain(repeat(array_without_nulls()).take(without_nulls as usize)) | ||
.collect(), | ||
) | ||
.unwrap(); | ||
|
||
b.iter(|| black_box(array.logical_nulls())) | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the added code comment match the implementation?
UnionArrays always returns a zero null_count. So this conditional
self.null_count() != 0
always evaluates to false, which means is never nullable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the proposed/added doc comments is what should happen -- but it's not happening now.
Union types have no null validity bitmap (per spec). I believe this is why the null_count is always zero and the UnionArray::nulls is None.
In contrast, I believe the is_nullable is based on the child types (as the docs added here suggest). But what's missing is to define
UnionArray::is_nullable
on it's implementation, and in a way that examines the UnionArray's children. (Dictionary arrays already does so.) Do you agree?If you agree, then maybe add this doc comment & the code change in a follow up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolute right, thank you!
I added an implementation always returning
true
just to not be buggy, and will improve in a follow up PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!