Skip to content

Commit

Permalink
ARROW-1712: [C++] Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xuepanchen committed Jan 23, 2018
1 parent 360e601 commit 707b67b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
30 changes: 17 additions & 13 deletions cpp/src/arrow/array-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1154,40 +1154,44 @@ TEST_F(TestBinaryBuilder, TestScalarAppend) {
}
}
}

TEST_F(TestBinaryBuilder, TestCapacityReserve) {
vector<string> strings = {"aaaaa", "bbbbbbbbbb", "ccccccccccccccc", "dddddddddddddddddddd", "eeeeeeeeee"};
vector<string> strings = {"aaaaa", "bbbbbbbbbb", "ccccccccccccccc", "dddddddddd"};
int N = static_cast<int>(strings.size());
int reps = 10;
int reps = 15;
int64_t length = 0;
int64_t capacity = 1000;

int64_t expected_capacity = BitUtil::RoundUpToMultipleOf64(capacity);

ASSERT_OK(builder_->ReserveData(capacity));

ASSERT_EQ(length, builder_->value_data_length());
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(capacity), builder_->value_data_capacity());
ASSERT_EQ(expected_capacity, builder_->value_data_capacity());

for (int j = 0; j < reps; ++j) {
for (int i = 0; i < N; ++i) {
ASSERT_OK(builder_->Append(strings[i]));
length += static_cast<int>(strings[i].size());

ASSERT_EQ(length, builder_->value_data_length());
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(capacity), builder_->value_data_capacity());
ASSERT_EQ(expected_capacity, builder_->value_data_capacity());
}
}

int extra_capacity = 500;
expected_capacity = BitUtil::RoundUpToMultipleOf64(length + extra_capacity);

ASSERT_OK(builder_->ReserveData(extra_capacity));

ASSERT_EQ(length, builder_->value_data_length());
ASSERT_EQ(BitUtil::RoundUpToMultipleOf64(length + extra_capacity), builder_->value_data_capacity());
ASSERT_EQ(expected_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(length + extra_capacity), result_->value_data()->capacity());
ASSERT_EQ(reps * 40, result_->value_data()->size());
ASSERT_EQ(expected_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 @@ -1225,14 +1225,14 @@ Status BinaryBuilder::Resize(int64_t capacity) {
RETURN_NOT_OK(offsets_builder_.Resize((capacity + 1) * sizeof(int32_t)));
return ArrayBuilder::Resize(capacity);
}

Status BinaryBuilder::ReserveData(int64_t elements) {
if (value_data_length() + elements > value_data_capacity()) {
if (value_data_length() + elements > std::numeric_limits<int32_t>::max()) {
return Status::Invalid("Cannot reserve capacity larger than 2^31 - 1 in length for binary data");
return Status::Invalid("Cannot reserve capacity larger than 2^31 - 1 for binary");
}
RETURN_NOT_OK(value_data_builder_.Reserve(elements));
}
}
return Status::OK();
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class ARROW_EXPORT BinaryBuilder : public ArrayBuilder {

Status Init(int64_t elements) override;
Status Resize(int64_t capacity) override;
/// \brief Ensures there is enough allocated capacity to append the indicated
/// \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 707b67b

Please sign in to comment.