Skip to content

Commit

Permalink
ARROW-1712: [C++] Modify test case for BinaryBuilder::ReserveData() a…
Browse files Browse the repository at this point in the history
…nd change arguments for offsets_builder_.Resize()
  • Loading branch information
xuepanchen committed Jan 22, 2018
1 parent bc5db7d commit d4bbd15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions cpp/src/arrow/array-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,6 @@ TEST_F(TestBinaryBuilder, TestCapacityReserve) {
int64_t length = 0;
int64_t capacity = 1000;


ASSERT_OK(builder_->ReserveData(capacity));

ASSERT_EQ(length, builder_->value_data_length());
Expand All @@ -1177,11 +1176,18 @@ TEST_F(TestBinaryBuilder, TestCapacityReserve) {
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(capacity), builder_->value_data_capacity());
}
}

int extra_capacity = 500;
ASSERT_OK(builder_->ReserveData(extra_capacity));

ASSERT_EQ(length, builder_->value_data_length());
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(length + extra_capacity), builder_->value_data_capacity());

Done();
ASSERT_EQ(reps * N, result_->length());
ASSERT_EQ(0, result_->null_count());
ASSERT_EQ(reps * 60, result_->value_data()->size());
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(capacity), result_->value_data()->capacity());
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(length + extra_capacity), result_->value_data()->capacity());
}

TEST_F(TestBinaryBuilder, TestZeroLength) {
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1165,13 +1165,13 @@ Status ListBuilder::Init(int64_t elements) {
DCHECK_LT(elements, std::numeric_limits<int32_t>::max());
RETURN_NOT_OK(ArrayBuilder::Init(elements));
// one more then requested for offsets
return offsets_builder_.Resize((elements + 1) * sizeof(int64_t));
return offsets_builder_.Resize((elements + 1) * sizeof(int32_t));
}

Status ListBuilder::Resize(int64_t capacity) {
DCHECK_LT(capacity, std::numeric_limits<int32_t>::max());
// one more then requested for offsets
RETURN_NOT_OK(offsets_builder_.Resize((capacity + 1) * sizeof(int64_t)));
RETURN_NOT_OK(offsets_builder_.Resize((capacity + 1) * sizeof(int32_t)));
return ArrayBuilder::Resize(capacity);
}

Expand Down Expand Up @@ -1216,7 +1216,7 @@ Status BinaryBuilder::Init(int64_t elements) {
DCHECK_LT(elements, std::numeric_limits<int32_t>::max());
RETURN_NOT_OK(ArrayBuilder::Init(elements));
// one more then requested for offsets
return offsets_builder_.Resize((elements + 1) * sizeof(int64_t));
return offsets_builder_.Resize((elements + 1) * sizeof(int32_t));
}

Status BinaryBuilder::Resize(int64_t capacity) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ class ARROW_EXPORT BinaryBuilder : public ArrayBuilder {

Status Init(int64_t elements) override;
Status Resize(int64_t capacity) override;
/// Ensures there is enough space for adding the number of value elements
/// by checking value buffer capacity and resizing if necessary.
/// \brief Ensures there is enough allocated capacity to append the indicated
/// number of bytes to the value data buffer without additional allocations
Status ReserveData(int64_t elements);
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;

Expand Down

0 comments on commit d4bbd15

Please sign in to comment.