zanmato1984 commented on code in PR #55253:
URL: https://github.com/apache/arrow/pull/55253#discussion_r4582579592
##########
cpp/src/arrow/compute/kernels/vector_hash.cc:
##########
@@ -513,15 +515,25 @@ class DictionaryHashKernel : public HashKernel {
return first_dictionary_;
}
- auto out_dict_type = first_dictionary_->type();
+ std::shared_ptr<DataType> out_dict_type;
std::shared_ptr<Array> out_dict;
RETURN_NOT_OK(dictionary_unifier_->GetResult(&out_dict_type, &out_dict));
+ // The output keeps the input index type, so the highest index into the
unified
+ // dictionary (its length minus one) must fit in it
+ const Int64Scalar max_index(out_dict->length() - 1);
+ if (out_dict->length() > 0 &&
+ !::arrow::internal::IntegersCanFit(max_index, *index_type_).ok()) {
Review Comment:
I independently reproduced the valid-input regression Dmitry described. A
unified dictionary can contain 129 entries while the only used indices are 0
and 64, which still fit in int8.
Could we check the used non-null transposed indices before narrowing, and
add this valid-input case for both unique and value_counts alongside the
existing boundary tests? Please also assert the actual result values and
counts, rather than relying only on ValidateFull().
--
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]