R-JunmingChen commented on code in PR #37418:
URL: https://github.com/apache/arrow/pull/37418#discussion_r1351216990


##########
cpp/src/arrow/array/array_dict.cc:
##########
@@ -211,6 +212,92 @@ Result<std::shared_ptr<ArrayData>> TransposeDictIndices(
   return out_data;
 }
 
+template <typename IndexArrowType>
+Result<std::unique_ptr<Buffer>> CompactTransposeMapImpl(
+    const std::shared_ptr<ArrayData>& data, MemoryPool* pool,
+    std::shared_ptr<Array>& out_compact_dictionary) {
+  int64_t index_length = data->length;
+  int64_t dict_length = data->dictionary->length;
+  if (index_length == 0 || dict_length == 0) {
+    ARROW_ASSIGN_OR_RAISE(out_compact_dictionary,
+                          MakeEmptyArray(data->dictionary->type, pool));
+    return AllocateBuffer(0, pool);
+  }
+
+  using CType = typename IndexArrowType::c_type;
+  const CType* indices_data = data->GetValues<CType>(1);
+  std::vector<bool> dict_used(dict_length, false);
+  CType dict_len = static_cast<CType>(dict_length);
+  for (int64_t i = 0; i < index_length; i++) {
+    if (data->IsNull(i)) {
+      continue;
+    }
+
+    CType current_index = indices_data[i];
+    if (current_index < 0 || current_index >= dict_len) {
+      return Status::IndexError("indice out of bound:", current_index);
+    } else if (!dict_used[current_index]) {
+      dict_used[current_index] = true;
+    }
+  }
+

Review Comment:
   I reuse the old version code to check compaction in advance



-- 
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