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

Use NullBuffer in ArrayData (#3775) #3778

Merged
merged 6 commits into from
Mar 2, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Feb 28, 2023

Which issue does this PR close?

Closes #3775
Part of #1799
Part of #1176

Rationale for this change

See ticket, but we need to switch to a null buffer representation that can store its offset separately from the ArrayData it belongs to. There isn't an obvious way to add support for this without a breaking change. Fortunately most downstreams are not interacting with the null buffers directly, and so the impact of this change shouldn't be too problematic.

What changes are included in this PR?

Are there any user-facing changes?

@tustvold tustvold added the api-change Changes to the arrow API label Feb 28, 2023
@github-actions github-actions bot added arrow Changes to the arrow crate parquet Changes to the parquet crate labels Feb 28, 2023
None => {
let len_bytes = ceil(len, 8);
MutableBuffer::new(len_bytes)
.with_bitset(len_bytes, true)
.into()
}
Some(buffer) => buffer.bit_slice(input.offset(), len),
Some(nulls) => nulls.inner().sliced(),
Copy link
Contributor Author

@tustvold tustvold Feb 28, 2023

Choose a reason for hiding this comment

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

Eventually the use of a sliceable NullBuffer will allow us to not need to slice the buffer, and instead just preserve the offset, but I wanted to keep the changes in this PR down

@@ -481,9 +481,10 @@ mod tests {
assert_eq!(batches.len(), 1);

let list = as_list_array(batches[0].column(0).as_ref());
assert_eq!(list.len(), 3);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was wrong, it was checking nulls beyond the bounds of the NullBuffer. This was working because previously the length enforcement was at the byte level (i.e. multiple of 8)

@tustvold
Copy link
Contributor Author

tustvold commented Mar 1, 2023

apache/datafusion#5441 shows this causing extremely limited downstream churn to DataFusion 🎉

Edit: I have also confirmed this does not regress the benchmarks

@tustvold tustvold marked this pull request as ready for review March 1, 2023 13:49
@@ -249,23 +249,15 @@ impl<K: ArrowPrimitiveType> DictionaryArray<K> {

// Note: This use the ArrayDataBuilder::build_unchecked and afterwards
// call the new function which only validates that the keys are in bounds.
let mut data = ArrayData::builder(dict_data_type)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually previously wrong, as it doesn't preserve the offset of the input array

pub fn slice(&self, offset: usize, len: usize) -> Self {
assert!(
offset.saturating_add(len) <= self.len,
"the offset of the new BooleanBuffer cannot exceed the existing length"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"the offset of the new BooleanBuffer cannot exceed the existing length"
"the offset + length of the new BooleanBuffer cannot exceed the existing length"

@@ -69,11 +86,28 @@ impl NullBuffer {
!self.is_valid(idx)
}

/// Returns the inner buffer
/// Returns the packed validity of this [`BooleanBuffer`] not including any offset
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Returns the packed validity of this [`BooleanBuffer`] not including any offset
/// Returns the packed validity of inner [`BooleanBuffer`] of this [`NullBuffer`] not including any offset

@@ -1704,6 +1710,7 @@ pub struct ArrayDataBuilder {
len: usize,
null_count: Option<usize>,
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need null_count in this builder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, so that we can support use-cases that provide null_bit_buffer instead of NullBuffer

@tustvold tustvold merged commit eff058f into apache:master Mar 2, 2023
@ursabot
Copy link

ursabot commented Mar 2, 2023

Benchmark runs are scheduled for baseline = 7852e76 and contender = eff058f. eff058f 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
api-change Changes to the arrow API arrow Changes to the arrow crate parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use NullBuffer in ArrayData
3 participants