Skip to content

Commit

Permalink
fix nits and test
Browse files Browse the repository at this point in the history
  • Loading branch information
micah-white committed May 11, 2023
1 parent d10fe67 commit d55a593
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cpp/src/arrow/scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ struct ScalarHashImpl {

Status ArrayHash(const ArrayData& a) {
RETURN_NOT_OK(StdHash(a.length) & StdHash(a.GetNullCount()));
if (a.GetNullCount() != 0) {
if (a.GetNullCount() != 0 && a.buffers[0] != nullptr) {
// We can't visit values without unboxing the whole array, so only hash
// the null bitmap for now. Only hash the null bitmap if the null count
// is 0 to ensure hash consistency.
// is not 0 to ensure hash consistency.
RETURN_NOT_OK(BufferHash(*a.buffers[0]));
}
for (const auto& child : a.child_data) {
Expand Down
18 changes: 6 additions & 12 deletions cpp/src/arrow/scalar_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1111,18 +1111,12 @@ class TestListScalar : public ::testing::Test {
ASSERT_OK(empty_bitmap_scalar.ValidateFull());
ASSERT_TRUE(empty_bitmap_scalar.value->data()->buffers[0] == nullptr);

auto data = empty_bitmap_scalar.value->data()->buffers[1];
std::vector<uint8_t> bitmap_data = {0,0,0};
auto null_bitmap = std::make_shared<Buffer>(bitmap_data.data(), 3);

std::shared_ptr<Int16Array> arr(new Int16Array(3, data, null_bitmap, 0));
ASSERT_TRUE(arr->null_count() == 0);
// this line fails - I don't know how to create an array with a null bitmap
// that is all 0s.
ASSERT_TRUE(arr->data()->buffers[0] != nullptr);
ScalarType set_bitmap_scalar(arr);

ASSERT_TRUE(set_bitmap_scalar.hash() == empty_bitmap_scalar.hash());
auto list_array = ArrayFromJSON(type_, "[[1, 2, 3], [4, 5, null]]");
ASSERT_OK_AND_ASSIGN(auto set_bitmap_scalar_uncasted, list_array->GetScalar(0));
auto set_bitmap_scalar = std::dynamic_pointer_cast<ScalarType>(set_bitmap_scalar_uncasted);
ASSERT_TRUE(set_bitmap_scalar != nullptr);
ASSERT_TRUE(set_bitmap_scalar->value->data()->buffers[0] != nullptr);
ASSERT_TRUE(empty_bitmap_scalar.hash() == set_bitmap_scalar->hash());
}

protected:
Expand Down

0 comments on commit d55a593

Please sign in to comment.