Skip to content

GH-55503: [C++] Fix Float16 memo table keys built from raw bits - #55610

Closed
AnuragRaut08 wants to merge 1 commit into
apache:mainfrom
AnuragRaut08:fix/float16-dictionary-count-distinct
Closed

AnuragRaut08 wants to merge 1 commit into
apache:mainfrom
AnuragRaut08:fix/float16-dictionary-count-distinct

Conversation

@AnuragRaut08

@AnuragRaut08 AnuragRaut08 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Float16 dictionary unification and count_distinct produce incorrect results because raw uint16_t storage values are interpreted as numeric values instead of Float16 bit patterns.

For example, the Float16 bit pattern 0x3C00, representing 1.0, is interpreted as 15360.0 when passed through the converting constructor.

This causes dictionary values to be corrupted during dictionary unification and distinct Float16 values to be incorrectly merged by count_distinct.

What changes are included in this PR?

  • Use Float16::FromBits() when constructing memo table keys from raw Float16 values in DictionaryUnifierImpl::Unify.
  • Fix Float16 handling in the array path of CountDistinctImpl::Consume.
  • Fix Float16 scalar unboxing to preserve the original bit representation in UnboxScalar<HalfFloatType>::Unbox.

Are these changes tested?

Added regression tests:

  • TestDictionaryUnifier.HalfFloat: verifies unified dictionary values and transpose maps.
  • TestCountDistinctKernel.HalfFloat: covers distinct Float16 values, duplicates, nulls, chunked arrays, and scalar input.

Verified that both new regression tests fail with the original implementation and pass with the fix.

Validation performed:

  • arrow-array-test: 346 tests passed (2 disabled).
  • arrow-compute-aggregate-test: 346 tests passed.
  • clang-format --dry-run --Werror: passed.
  • git diff --check: passed.

Are there any user-facing changes?

Fixes incorrect Float16 values returned by dictionary unification and incorrect distinct counts for Float16 arrays.

Critical Fix

This PR fixes a bug that produces incorrect data. Float16 dictionary values could be corrupted during unification, and count_distinct could undercount distinct Float16 values.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55503 has been automatically assigned in GitHub to PR creator.

@Reranko05

Copy link
Copy Markdown
Collaborator

We don't need AI only contribution.

@Reranko05 Reranko05 closed this Nov 14, 2026
@AnuragRaut08

Copy link
Copy Markdown
Contributor Author

@Reranko05 I understand the concern about AI-generated contributions.

I did use AI assistance during development, but I want to clarify that I personally worked through the reproduction, ran the regression tests against the original implementation, validated the fix, and checked the affected code paths.

I'm happy to explain the implementation and the reasoning behind each change. If there are specific concerns about the contribution or its implementation, I'd appreciate the opportunity to address them.

I respect the project's contribution guidelines and will make sure my future contributions demonstrate that ownership more clearly.

@Reranko05

Copy link
Copy Markdown
Collaborator

Thanks for clarifying. The PR was closed because the AI declaration in the description indicated that the code was written and reviewed only by AI, with no human review selected.

As per Apache Arrow's contribution policy, AI-assisted contributions require human review before submission. https://arrow.apache.org/docs/developers/overview.html#ai-generated-code

You're welcome to open a new PR with the changes properly reviewed by a human and the AI declaration updated accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants