Skip to content
Open
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
8 changes: 8 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ KernelInit GetHashInit(Type::type type_id) {
return HashInit<RegularHashKernel<UInt8Type, Action>>;
case Type::INT16:
case Type::UINT16:
case Type::HALF_FLOAT:
return HashInit<RegularHashKernel<UInt16Type, Action>>;
case Type::INT32:
case Type::UINT32:
Expand Down Expand Up @@ -700,6 +701,13 @@ void AddHashKernels(VectorFunction* func, VectorKernel base, OutputType out_ty)
DCHECK_OK(func->AddKernel(base));
}

// float16() is not part of PrimitiveTypes() (FloatingPointTypes() only covers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we open a separate issue for FloatingPointTypes? I think we should make float16 part of it.

// float32 and float64; see GH-43017), so it must be registered explicitly. Like
// float32 and float64, it is hashed by its raw bit pattern (via UInt16Type).
base.init = GetHashInit<Action>(Type::HALF_FLOAT);
base.signature = KernelSignature::Make({float16()}, out_ty);
DCHECK_OK(func->AddKernel(base));

// Parametric types that we want matching to be dependent only on type id
auto parametric_types = {Type::TIME32, Type::TIME64, Type::TIMESTAMP, Type::DURATION,
Type::FIXED_SIZE_BINARY};
Expand Down
38 changes: 38 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_hash_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,44 @@ TEST_F(TestHashKernel, DictEncodeBoolean) {
ArrayFromJSON(boolean(), "[true]"), ArrayFromJSON(int32(), "[0, null, 0]"));
}

// float16 is not part of PrimitiveTypes(), so it is not covered by
// TestHashKernelPrimitive above and gets its own coverage here. Like float32 and
// float64, it is hashed by its raw bit pattern.
Comment on lines +406 to +408

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, can we fix TestHashKernelPrimitive so that it also covers HalfFloatType?

TEST_F(TestHashKernel, UniqueHalfFloat) {
CheckUnique(ArrayFromJSON(float16(), "[1.5, 2.5, null, 1.5, 3.5, null]"),
ArrayFromJSON(float16(), "[1.5, 2.5, null, 3.5]"));

// No nulls
CheckUnique(ArrayFromJSON(float16(), "[1.5, 2.5, 1.5, 3.5]"),
ArrayFromJSON(float16(), "[1.5, 2.5, 3.5]"));

// Sliced
CheckUnique(ArrayFromJSON(float16(), "[1.5, 2.5, null, 3.5, 2.5, 1.5]")->Slice(1, 4),
ArrayFromJSON(float16(), "[2.5, null, 3.5]"));
}

TEST_F(TestHashKernel, ValueCountsHalfFloat) {
CheckValueCounts(ArrayFromJSON(float16(), "[1.5, 2.5, null, 1.5, 3.5, null]"),
ArrayFromJSON(float16(), "[1.5, 2.5, null, 3.5]"),
ArrayFromJSON(int64(), "[2, 1, 2, 1]"));
}

TEST_F(TestHashKernel, DictEncodeHalfFloat) {
CheckDictEncode(ArrayFromJSON(float16(), "[1.5, 2.5, null, 1.5, 3.5, null]"),
ArrayFromJSON(float16(), "[1.5, 2.5, 3.5]"),
ArrayFromJSON(int32(), "[0, 1, null, 0, 2, null]"));

// No nulls
CheckDictEncode(ArrayFromJSON(float16(), "[1.5, 2.5, 1.5, 3.5]"),
ArrayFromJSON(float16(), "[1.5, 2.5, 3.5]"),
ArrayFromJSON(int32(), "[0, 1, 0, 2]"));

// Sliced
CheckDictEncode(
ArrayFromJSON(float16(), "[1.5, 2.5, null, 3.5, 2.5, 1.5]")->Slice(1, 4),
ArrayFromJSON(float16(), "[2.5, 3.5]"), ArrayFromJSON(int32(), "[0, null, 1, 0]"));
}

template <typename ArrowType>
class TestHashKernelBinaryTypes : public TestHashKernel {
protected:
Expand Down
Loading