Skip to content

Add set_bit to BooleanBufferBuilder to allow mutating bit in index#383

Merged
Dandandan merged 5 commits into
apache:masterfrom
boazberman:master
Jun 8, 2021
Merged

Add set_bit to BooleanBufferBuilder to allow mutating bit in index#383
Dandandan merged 5 commits into
apache:masterfrom
boazberman:master

Conversation

@boazberman

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Relates to apache/datafusion#240 & apache/datafusion#342

Rationale for this change

BooleanBufferBuilder behaves as a bitmap. My intention is to extend its API to allow mutating bits already set, to make it's API closer to the bitvec crate and useable for my use-case in arrow-datafusion.

What changes are included in this PR?

This PR includes the implementation and some tests that currently does not pass. I'm making the PR public to get help from the community, as I'm stuck.

Are there any user-facing changes?

There is a new public method set_bit added to BooleanBufferBuilder.

@Dandandan

Dandandan commented May 30, 2021

Copy link
Copy Markdown
Contributor

I added some details on the ASF Slack. I think the change is fine, but only the tests should be fixed.

Maybe it makes sense to expose get_bit as well? This also could make the tests a bit more intuitive.

@alamb

alamb commented May 31, 2021

Copy link
Copy Markdown
Contributor

FYI @tustvold

@alamb

alamb commented May 31, 2021

Copy link
Copy Markdown
Contributor

Thanks @boazberman !

Here is the Slack link @Dandandan is referring to: https://the-asf.slack.com/archives/C01QUFS30TD/p1622403410176000

FWIW @tustvold implemented some version of this logic in https://github.com/influxdata/influxdb_iox/blob/main/arrow_util/src/bitset.rs in case you want to have a friendly look (and perhaps we can eventually use BooleanBufferBuilder rather than our own bitset creator,

@boaz-codota

boaz-codota commented Jun 5, 2021

Copy link
Copy Markdown
Contributor

Fix the tests, could you review? @Dandandan @alamb ?

Also, @alamb I noticed that in https://github.com/influxdata/influxdb_iox/blob/main/arrow_util/src/bitset.rs#L87 is differ from what is done here:

// influx_iox
data[i >> 3] |= 1 << (i & 7) 

vs

// arrow-rs
const BIT_MASK: [u8; 8] = [1, 2, 4, 8, 16, 32, 64, 128];
// ...
data[i >> 3] |= BIT_MASK[i & 7];

which I haven't tested but might have performance implications (?)

Comment thread arrow/src/array/builder.rs Outdated
}

#[inline]
pub fn set_bit(&mut self, index: usize, bit: bool) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn set_bit(&mut self, index: usize, bit: bool) {
pub fn set_bit(&mut self, index: usize, v: bool) {

(as called in other methods)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fixed

@Dandandan Dandandan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@codecov-commenter

codecov-commenter commented Jun 5, 2021

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.65%. Comparing base (0a16574) to head (2e28f7f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #383      +/-   ##
==========================================
+ Coverage   82.62%   82.65%   +0.02%     
==========================================
  Files         162      162              
  Lines       44479    44542      +63     
==========================================
+ Hits        36751    36814      +63     
  Misses       7728     7728              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alamb

alamb commented Jun 6, 2021

Copy link
Copy Markdown
Contributor

which I haven't tested but might have performance implications (?)

Hopefully the compiler can figure it out -- I think the way you have it is fine until we get some sort of profiling / performance measurements that show it isn't. 👍

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great @boazberman -- thank you!

Would it be possible to fix the rust clippy CI check? Then I think this is ready to merge in.

🥇 for tests 👍

@boaz-codota

Copy link
Copy Markdown
Contributor

@alamb fixed clippy failures

@boaz-codota

Copy link
Copy Markdown
Contributor

hey, what is blocking this from being merged? @Dandandan @alamb

@Dandandan Dandandan merged commit 18c804a into apache:master Jun 8, 2021
@Dandandan

Copy link
Copy Markdown
Contributor

hey, what is blocking this from being merged? @Dandandan @alamb

Merged! Thank you 🚀

@alamb

alamb commented Jun 8, 2021

Copy link
Copy Markdown
Contributor

hey, what is blocking this from being merged? @Dandandan @alamb

Lack of time :) Sorry about that @boaz-codota -- thanks for following up and thanks for merging @Dandandan 👍

alamb pushed a commit that referenced this pull request Jun 8, 2021
)

* Add set_bit to BooleanBufferBuilder to allow mutating bits in the builder

* Fix tests

* Update builder.rs

* Update builder.rs

* Fix clippy failures

Co-authored-by: Boaz Berman <boaz@codota.com>
alamb added a commit that referenced this pull request Jun 9, 2021
) (#431)

* Add set_bit to BooleanBufferBuilder to allow mutating bits in the builder

* Fix tests

* Update builder.rs

* Update builder.rs

* Fix clippy failures

Co-authored-by: Boaz Berman <boaz@codota.com>

Co-authored-by: Boaz <berman.boaz@gmail.com>
Co-authored-by: Boaz Berman <boaz@codota.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants