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
11 changes: 9 additions & 2 deletions cpp/src/arrow/array/dict_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,15 @@ struct DictionaryTraits<T, enable_if_binary_view_like<T>> {
BinaryViewBuilder builder(pool);
RETURN_NOT_OK(builder.Resize(memo_table.size() - start_offset));
RETURN_NOT_OK(builder.ReserveData(memo_table.values_size()));
memo_table.VisitValues(static_cast<int32_t>(start_offset),
[&](std::string_view s) { builder.UnsafeAppend(s); });
const int32_t null_index = memo_table.GetNull();
int32_t index = static_cast<int32_t>(start_offset);
memo_table.VisitValues(static_cast<int32_t>(start_offset), [&](std::string_view s) {
if (index++ == null_index) {
builder.UnsafeAppendNull();
} else {
builder.UnsafeAppend(s);
}
});

std::shared_ptr<ArrayData> out;
RETURN_NOT_OK(builder.FinishInternal(&out));
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_hash_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,18 @@ TYPED_TEST(TestHashKernelBinaryTypes, BinaryResizeTable) {
this->CheckDictEncodeP(values, {}, uniques, {}, indices);
}

TEST_F(TestHashKernel, UniqueBinaryViewWithNull) {
// GH-39635: the null slot must stay null in the unique values
for (const auto& type : {binary_view(), utf8_view()}) {
ARROW_SCOPED_TRACE(type->ToString());
CheckUnique(ArrayFromJSON(type, R"(["test", "a string that is not inlined", null,
"test"])"),
ArrayFromJSON(type, R"(["test", "a string that is not inlined", null])"));
CheckUnique(ArrayFromJSON(type, R"(["ab", null, "cd", "ab", null])")->Slice(1, 3),
ArrayFromJSON(type, R"([null, "cd", "ab"])"));
}
}

TEST_F(TestHashKernel, UniqueFixedSizeBinary) {
auto type = fixed_size_binary(3);

Expand Down
Loading