From d55a5932248dfba1af529c1cefbac15bddd99480 Mon Sep 17 00:00:00 2001 From: micah-white Date: Tue, 9 May 2023 20:04:14 -0500 Subject: [PATCH] fix nits and test --- cpp/src/arrow/scalar.cc | 4 ++-- cpp/src/arrow/scalar_test.cc | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/cpp/src/arrow/scalar.cc b/cpp/src/arrow/scalar.cc index 9c7c942683e58..1e40266b3caef 100644 --- a/cpp/src/arrow/scalar.cc +++ b/cpp/src/arrow/scalar.cc @@ -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) { diff --git a/cpp/src/arrow/scalar_test.cc b/cpp/src/arrow/scalar_test.cc index ae4821b0d25f1..e1bcfd8ef2fec 100644 --- a/cpp/src/arrow/scalar_test.cc +++ b/cpp/src/arrow/scalar_test.cc @@ -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 bitmap_data = {0,0,0}; - auto null_bitmap = std::make_shared(bitmap_data.data(), 3); - - std::shared_ptr 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(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: