Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cpp/src/arrow/array-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ void TestPrimitiveBuilder<PBoolean>::Check(const std::unique_ptr<BooleanBuilder>
ASSERT_EQ(draws_[i] != 0, actual) << i;
}
}
ASSERT_TRUE(result->Equals(*expected));
AssertArraysEqual(*result, *expected);

// buffers are correctly sized
ASSERT_EQ(result->data()->buffers[0]->size(), BitUtil::BytesForBits(size));
ASSERT_EQ(result->data()->buffers[1]->size(), BitUtil::BytesForBits(size));

// Builder is now reset
ASSERT_EQ(0, builder->length());
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/buffer-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ class TypedBufferBuilder<bool> {
}

Status Finish(std::shared_ptr<Buffer>* out, bool shrink_to_fit = true) {
// set bytes_builder_.size_ == byte size of data
bytes_builder_.UnsafeAdvance(BitUtil::BytesForBits(bit_length_) -
bytes_builder_.length());
Copy link
Member

Choose a reason for hiding this comment

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

Do these bytes need to be zeroed?

Copy link
Member Author

@bkietz bkietz Feb 15, 2019

Choose a reason for hiding this comment

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

TypedBufferBuilder<bool> doesn't utilize bytes_builder_'s append methods, which means the size of bytes_builder_ doesn't change as bits are appended.

I'm thinking it's not worthwhile to use BufferBuilder in this class, I'm going to refactor and instead just manage a buffer directly

Copy link
Member

Choose a reason for hiding this comment

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

OK, please do that refactoring in a follow up PR and not this one =)

bit_length_ = false_count_ = 0;
return bytes_builder_.Finish(out, shrink_to_fit);
}
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/buffer-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ TEST(TestBufferBuilder, BasicBoolBufferBuilderUsage) {
for (int i = 0; i != nvalues; ++i) {
ASSERT_EQ(BitUtil::GetBit(built->data(), i + 1), static_cast<bool>(values[i]));
}

ASSERT_EQ(built->size(), BitUtil::BytesForBits(nvalues + 1));
}

TEST(TestBufferBuilder, BoolBufferBuilderAppendCopies) {
Expand All @@ -367,6 +369,8 @@ TEST(TestBufferBuilder, BoolBufferBuilderAppendCopies) {
for (int i = 0; i != 13 + 17; ++i) {
EXPECT_EQ(BitUtil::GetBit(built->data(), i), i < 13) << "index = " << i;
}

ASSERT_EQ(built->size(), BitUtil::BytesForBits(13 + 17));
}

template <typename T>
Expand Down