bkietz commented on code in PR #38681:
URL: https://github.com/apache/arrow/pull/38681#discussion_r1394386688


##########
cpp/src/arrow/util/dict_util.cc:
##########
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/util/dict_util.h"
+#include "arrow/array/array_dict.h"
+#include "arrow/util/bit_util.h"
+#include "arrow/util/checked_cast.h"
+
+namespace arrow {
+namespace dict_util {
+
+namespace {
+
+template <typename IndexArrowType>
+int64_t LogicalNullCount(const ArraySpan& span) {
+  const auto* indices_null_bit_map = span.GetValues<uint8_t>(0);

Review Comment:
   This will break for sliced spans: since buffer 0 is a bitmap, using 
GetValues like this will account for offset incorrectly.



##########
cpp/src/arrow/array/array_test.cc:
##########
@@ -80,6 +80,22 @@ class TestArray : public ::testing::Test {
   MemoryPool* pool_;
 };
 
+void CheckDictionaryNullCount(const std::shared_ptr<DataType>& dict_type,
+                              const std::string& input_dictionary_json,
+                              const std::string& input_index_json,
+                              const int64_t& expected_null_count,
+                              const int64_t& expected_logical_null_count,
+                              bool expected_may_have_nulls,
+                              bool expected_may_have_logical_nulls) {
+  std::shared_ptr<arrow::Array> arr =
+      DictArrayFromJSON(dict_type, input_index_json, input_dictionary_json);
+
+  ASSERT_EQ(expected_null_count, arr->null_count());
+  ASSERT_EQ(expected_logical_null_count, arr->ComputeLogicalNullCount());
+  ASSERT_EQ(expected_may_have_nulls, arr->data()->MayHaveNulls());
+  ASSERT_EQ(expected_may_have_logical_nulls, 
arr->data()->MayHaveLogicalNulls());

Review Comment:
   Nit: prefer expectations as RHS
   ```suggestion
     ASSERT_EQ(arr->null_count(), expected_null_count);
     ASSERT_EQ(arr->ComputeLogicalNullCount(), expected_logical_null_count);
     ASSERT_EQ(arr->data()->MayHaveNulls(), expected_may_have_nulls);
     ASSERT_EQ(arr->data()->MayHaveLogicalNulls(), 
expected_may_have_logical_nulls);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to