Skip to content
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

Ignore null buffer when creating ArrayData if null count is zero #2056

Merged
merged 3 commits into from Jul 19, 2022

Conversation

jhorstmann
Copy link
Contributor

@jhorstmann jhorstmann commented Jul 12, 2022

Which issue does this PR close?

Closes #2055.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

Semantically a null buffer with all bits set / a null count of 0 is the same as a None null buffer, but this is an observable behavior change.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 12, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2022

Codecov Report

Merging #2056 (a0cac4d) into master (330505c) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2056      +/-   ##
==========================================
+ Coverage   83.55%   83.57%   +0.01%     
==========================================
  Files         222      222              
  Lines       58230    58244      +14     
==========================================
+ Hits        48656    48679      +23     
+ Misses       9574     9565       -9     
Impacted Files Coverage Δ
arrow/src/array/array_boolean.rs 94.15% <100.00%> (+0.77%) ⬆️
arrow/src/array/builder/generic_list_builder.rs 95.09% <0.00%> (-1.61%) ⬇️
...row/src/array/builder/string_dictionary_builder.rs 90.64% <0.00%> (-0.72%) ⬇️
arrow/src/datatypes/datatype.rs 65.31% <0.00%> (-0.37%) ⬇️
parquet_derive/src/parquet_field.rs 65.98% <0.00%> (-0.23%) ⬇️
arrow/src/array/equal/mod.rs 96.48% <0.00%> (+0.28%) ⬆️
arrow/src/ffi.rs 87.52% <0.00%> (+0.34%) ⬆️
arrow/src/compute/kernels/boolean.rs 97.69% <0.00%> (+0.88%) ⬆️
arrow/src/datatypes/ffi.rs 76.56% <0.00%> (+3.83%) ⬆️
arrow/src/array/builder/generic_string_builder.rs 92.13% <0.00%> (+10.08%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 330505c...a0cac4d. Read the comment docs.

Copy link
Contributor

@HaoYang670 HaoYang670 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the BooleanBuilder directly? I find it use the same logic:
https://github.com/apache/arrow-rs/blob/master/arrow/src/array/builder/boolean_builder.rs#L128-L138

If we don't do further optimization, I guess we could write the code like this:

    fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self {
        let iter = iter.into_iter();
        let (_, data_len) = iter.size_hint();
        let data_len = data_len.expect("Iterator must be sized"); // panic if no upper bound.
        let mut array_builder = BooleanBuilder::new(data_len);

        iter.for_each(|i| {
            array_builder.append_option(i.borrow().clone()).unwrap();
        });

        array_builder.finish()
    }

BTW, we could do some optimization in the BooleanBuilder, such as lazily materializing the null builder, just as what we have done in the primitive builder: https://github.com/apache/arrow-rs/blob/master/arrow/src/array/builder/primitive_builder.rs#L33-L35

@alamb
Copy link
Contributor

alamb commented Jul 13, 2022

Not sure what happened with the windows builder, but I have restarted the failed CI check and hopefully it will pass on rerun

@jhorstmann
Copy link
Contributor Author

Why don't we use the BooleanBuilder directly?

From a correctness perspective that would probably be better and would also solve the reliance on size_hint (#138). We would probably need to do some optimizations on the builders to get similar performance.

@HaoYang670
Copy link
Contributor

Why don't we use the BooleanBuilder directly?

We would probably need to do some optimizations on the builders to get similar performance.

Do you mean that the Boolean builder is slower than this implementation?

@tustvold
Copy link
Contributor

FWIW #2038 by @heyrutvik will overlap with this. This isn't a problem, just an FYI

@jhorstmann
Copy link
Contributor Author

#2038 looks like the more extensive and correct solution. I'll take a look at the performance results for that PR.

@heyrutvik
Copy link
Contributor

@jhorstmann FYI, see #2038 (comment) for some discussion about performance of the PR (and subsequent comments). I tried original value for buffer size for some builders but not seeing much difference.

@@ -242,14 +242,19 @@ impl<Ptr: Borrow<Option<bool>>> FromIterator<Ptr> for BooleanArray {
}
});

let null_buf: Buffer = null_builder.into();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could push this optimisation into ArrayData::new_unchecked??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea and it passes all the existing test cases. It also changes behavior when someone passes an explicit null buffer, but I can't think of a reason why people would rely on that.

@jhorstmann jhorstmann changed the title Avoid creating null buffer for BooleanArray if null count is zero Ignore null buffer when creating ArrayData if null count is zero Jul 18, 2022
@tustvold tustvold merged commit b2cf02c into apache:master Jul 19, 2022
@ursabot
Copy link

ursabot commented Jul 19, 2022

Benchmark runs are scheduled for baseline = efd3152 and contender = b2cf02c. b2cf02c is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BooleanArray::from_iter should omit validity buffer if all values are valid
8 participants