Skip to content

Commit

Permalink
also revert change to AdaptiveUIntBuilder::Append
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Sep 18, 2019
1 parent 4dfb55b commit 61ec25c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 1 addition & 9 deletions cpp/src/arrow/array/builder_adaptive.cc
Expand Up @@ -284,15 +284,7 @@ Status AdaptiveUIntBuilder::AppendValuesInternal(const uint64_t* values, int64_t
const int64_t chunk_size = std::min(length, kAdaptiveIntChunkSize);

uint8_t new_int_size;
if (values == pending_data_) {
// only the most recent addition to pending_data_ may expand int size
auto i = pending_pos_ - 1;
new_int_size = internal::DetectUIntWidth(
values + i, valid_bytes ? valid_bytes + i : nullptr, 1, int_size_);
} else {
new_int_size =
internal::DetectUIntWidth(values, valid_bytes, chunk_size, int_size_);
}
new_int_size = internal::DetectUIntWidth(values, valid_bytes, chunk_size, int_size_);

DCHECK_GE(new_int_size, int_size_);
if (new_int_size > int_size_) {
Expand Down
28 changes: 28 additions & 0 deletions cpp/src/arrow/array_test.cc
Expand Up @@ -1478,6 +1478,20 @@ TEST_F(TestAdaptiveIntBuilder, TestInt16) {
AssertArraysEqual(*expected_, *result_);
}

TEST_F(TestAdaptiveIntBuilder, TestInt16Nulls) {
ASSERT_OK(builder_->Append(0));
ASSERT_EQ(builder_->type()->id(), Type::INT8);
ASSERT_OK(builder_->Append(128));
ASSERT_EQ(builder_->type()->id(), Type::INT16);
ASSERT_OK(builder_->AppendNull());
ASSERT_EQ(builder_->type()->id(), Type::INT16);
Done();

std::vector<int16_t> expected_values({0, 128, 0});
ArrayFromVector<Int16Type, int16_t>({1, 1, 0}, expected_values, &expected_);
ASSERT_ARRAYS_EQUAL(*expected_, *result_);
}

TEST_F(TestAdaptiveIntBuilder, TestInt32) {
ASSERT_OK(builder_->Append(0));
ASSERT_EQ(builder_->type()->id(), Type::INT8);
Expand Down Expand Up @@ -1681,6 +1695,20 @@ TEST_F(TestAdaptiveUIntBuilder, TestUInt16) {
ASSERT_TRUE(expected_->Equals(result_));
}

TEST_F(TestAdaptiveUIntBuilder, TestUInt16Nulls) {
ASSERT_OK(builder_->Append(0));
ASSERT_EQ(builder_->type()->id(), Type::UINT8);
ASSERT_OK(builder_->Append(256));
ASSERT_EQ(builder_->type()->id(), Type::UINT16);
ASSERT_OK(builder_->AppendNull());
ASSERT_EQ(builder_->type()->id(), Type::UINT16);
Done();

std::vector<uint16_t> expected_values({0, 256, 0});
ArrayFromVector<UInt16Type, uint16_t>({1, 1, 0}, expected_values, &expected_);
ASSERT_ARRAYS_EQUAL(*expected_, *result_);
}

TEST_F(TestAdaptiveUIntBuilder, TestUInt32) {
ASSERT_OK(builder_->Append(0));
ASSERT_EQ(builder_->type()->id(), Type::UINT8);
Expand Down

0 comments on commit 61ec25c

Please sign in to comment.