Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion cpp/cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ function(ADD_ARROW_TEST REL_TEST_NAME)
APPEND_STRING PROPERTY
COMPILE_FLAGS " -DARROW_VALGRIND")
add_test(${TEST_NAME}
bash -c "cd ${EXECUTABLE_OUTPUT_PATH}; valgrind --tool=memcheck --leak-check=full --leak-check-heuristics=stdstring --error-exitcode=1 ${TEST_PATH}")
bash -c "cd '${CMAKE_SOURCE_DIR}'; \
valgrind --suppressions=valgrind.supp --tool=memcheck --gen-suppressions=all \
--leak-check=full --leak-check-heuristics=stdstring --error-exitcode=1 ${TEST_PATH}")
elseif(MSVC)
add_test(${TEST_NAME} ${TEST_PATH})
else()
Expand Down
49 changes: 34 additions & 15 deletions cpp/src/arrow/array-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ TEST_F(TestArray, TestIsNullIsValid) {
}
}

TEST_F(TestArray, TestIsNullIsValidNoNulls) {
const int64_t size = 10;

std::unique_ptr<Array> arr;
arr.reset(new Int32Array(size, nullptr, nullptr, 0));

for (size_t i = 0; i < size; ++i) {
EXPECT_TRUE(arr->IsValid(i));
EXPECT_FALSE(arr->IsNull(i));
}
}

TEST_F(TestArray, BuildLargeInMemoryArray) {
const int64_t length = static_cast<int64_t>(std::numeric_limits<int32_t>::max()) + 1;

Expand Down Expand Up @@ -373,46 +385,50 @@ int64_t TestPrimitiveBuilder<PBoolean>::FlipValue(int64_t value) const {
template <>
void TestPrimitiveBuilder<PBoolean>::Check(const std::unique_ptr<BooleanBuilder>& builder,
bool nullable) {
int64_t size = builder->length();
const int64_t size = builder->length();

// Build expected result array
std::shared_ptr<Buffer> ex_data;
ASSERT_OK(BitUtil::BytesToBits(draws_, default_memory_pool(), &ex_data));

std::shared_ptr<Buffer> ex_null_bitmap;
int64_t ex_null_count = 0;

ASSERT_OK(BitUtil::BytesToBits(draws_, default_memory_pool(), &ex_data));
if (nullable) {
ASSERT_OK(BitUtil::BytesToBits(valid_bytes_, default_memory_pool(), &ex_null_bitmap));
ex_null_count = test::null_count(valid_bytes_);
} else {
ex_null_bitmap = nullptr;
}

auto expected =
std::make_shared<BooleanArray>(size, ex_data, ex_null_bitmap, ex_null_count);
ASSERT_EQ(size, expected->length());

// Finish builder and check result array
std::shared_ptr<Array> out;
ASSERT_OK(builder->Finish(&out));
std::shared_ptr<BooleanArray> result = std::dynamic_pointer_cast<BooleanArray>(out);

// Builder is now reset
ASSERT_EQ(0, builder->length());
ASSERT_EQ(0, builder->capacity());
ASSERT_EQ(0, builder->null_count());
ASSERT_EQ(nullptr, builder->data());

ASSERT_EQ(ex_null_count, result->null_count());
ASSERT_EQ(size, result->length());

ASSERT_EQ(expected->length(), result->length());

for (int64_t i = 0; i < result->length(); ++i) {
for (int64_t i = 0; i < size; ++i) {
if (nullable) {
ASSERT_EQ(valid_bytes_[i] == 0, result->IsNull(i)) << i;
} else {
ASSERT_FALSE(result->IsNull(i));
}
if (!result->IsNull(i)) {
bool actual = BitUtil::GetBit(result->values()->data(), i);
ASSERT_EQ(draws_[i] != 0, actual) << i;
}
bool actual = BitUtil::GetBit(result->values()->data(), i);
ASSERT_EQ(draws_[i] != 0, actual) << i;
}
ASSERT_TRUE(result->Equals(*expected));

// Builder is now reset
ASSERT_EQ(0, builder->length());
ASSERT_EQ(0, builder->capacity());
ASSERT_EQ(0, builder->null_count());
ASSERT_EQ(nullptr, builder->data());
}

typedef ::testing::Types<PBoolean, PUInt8, PUInt16, PUInt32, PUInt64, PInt8, PInt16,
Expand Down Expand Up @@ -633,6 +649,9 @@ TYPED_TEST(TestPrimitiveBuilder, TestAppendValues) {
ASSERT_EQ(size, this->builder_->length());
ASSERT_EQ(BitUtil::NextPower2(size), this->builder_->capacity());

ASSERT_EQ(size, this->builder_nn_->length());
ASSERT_EQ(BitUtil::NextPower2(size), this->builder_nn_->capacity());

this->Check(this->builder_, true);
this->Check(this->builder_nn_, false);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ARROW_EXPORT Array {
/// \brief Return true if value at index is valid (not null). Does not
/// boundscheck
bool IsValid(int64_t i) const {
return null_bitmap_data_ != NULLPTR &&
return null_bitmap_data_ == NULLPTR ||
BitUtil::GetBit(null_bitmap_data_, i + data_->offset);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this

}

Expand Down
24 changes: 24 additions & 0 deletions cpp/src/arrow/builder-benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ static void BM_BuildAdaptiveUIntNoNulls(
state.SetBytesProcessed(state.iterations() * data.size() * sizeof(int64_t));
}

static void BM_BuildBooleanArrayNoNulls(
benchmark::State& state) { // NOLINT non-const reference
// 2 MiB block
std::vector<uint8_t> data(2 * 1024 * 1024);
constexpr uint8_t bit_pattern = 0xcc; // 0b11001100
uint64_t index = 0;
std::generate(data.begin(), data.end(),
[&index]() -> uint8_t { return (bit_pattern >> ((index++) % 8)) & 1; });

while (state.KeepRunning()) {
BooleanBuilder builder;
for (int i = 0; i < kFinalSize; i++) {
// Build up an array of 512 MiB in size
ABORT_NOT_OK(builder.AppendValues(data.data(), data.size()));
}
std::shared_ptr<Array> out;
ABORT_NOT_OK(builder.Finish(&out));
}
state.SetBytesProcessed(state.iterations() * data.size() * kFinalSize);
}

static void BM_BuildBinaryArray(benchmark::State& state) { // NOLINT non-const reference
const int64_t iterations = 1 << 20;

Expand Down Expand Up @@ -152,6 +173,9 @@ static void BM_BuildFixedSizeBinaryArray(

BENCHMARK(BM_BuildPrimitiveArrayNoNulls)->Repetitions(3)->Unit(benchmark::kMicrosecond);
BENCHMARK(BM_BuildVectorNoNulls)->Repetitions(3)->Unit(benchmark::kMicrosecond);

BENCHMARK(BM_BuildBooleanArrayNoNulls)->Repetitions(3)->Unit(benchmark::kMicrosecond);

BENCHMARK(BM_BuildAdaptiveIntNoNulls)->Repetitions(3)->Unit(benchmark::kMicrosecond);
BENCHMARK(BM_BuildAdaptiveIntNoNullsScalarAppend)
->Repetitions(3)
Expand Down
Loading