Skip to content

GH-50624: [C++][Compute] Tighten case_when exact dispatch for parameterized types#50625

Open
zanmato1984 wants to merge 1 commit into
apache:mainfrom
zanmato1984:codex/case-when-parameterized-exact-dispatch
Open

GH-50624: [C++][Compute] Tighten case_when exact dispatch for parameterized types#50625
zanmato1984 wants to merge 1 commit into
apache:mainfrom
zanmato1984:codex/case-when-parameterized-exact-dispatch

Conversation

@zanmato1984

Copy link
Copy Markdown
Contributor

Rationale for this change

case_when exact dispatch was too permissive for parameterized value types. When the value arguments were registered by type id only, DispatchExact could incorrectly accept incompatible concrete types and return successful but corrupted results instead of failing or falling back to DispatchBest.

This fixes #50624.

What changes are included in this PR?

  • rename the case_when exact-match helper to AllValueTypesMatchConstraint() to make its intent explicit
  • apply the same exact-match constraint across case_when value kernels so exact dispatch only accepts identical value DataTypes
  • add regression coverage for mismatched parameterized value types, including fixed_size_binary, list, fixed_size_list, struct, and dictionary exact-dispatch mismatches

Are these changes tested?

Yes.

This PR extends TestCaseWhen.DispatchExact and adds TestCaseWhen.ParameterizedValueTypeMismatch. I also ran targeted arrow-compute-scalar-if-else-test coverage for:

  • TestCaseWhen.DispatchExact
  • TestCaseWhen.DispatchBest
  • TestCaseWhen.ParameterizedValueTypeMismatch

Are there any user-facing changes?

Yes.

case_when now rejects incompatible parameterized value types that previously could be incorrectly exact-dispatched, which could lead to corrupted results.

This PR contains a "Critical Fix". It fixes a bug where case_when could return successful but corrupted results for incompatible parameterized value types.

@zanmato1984
zanmato1984 marked this pull request as ready for review July 24, 2026 00:52
@zanmato1984
zanmato1984 requested a review from pitrou as a code owner July 24, 2026 00:52
Copilot AI review requested due to automatic review settings July 24, 2026 00:52
@zanmato1984 zanmato1984 added the Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. label Jul 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens case_when kernel selection so exact dispatch only accepts identical concrete DataTypes for value arguments (including parameterized/nested types), preventing incorrect kernel matches that could previously yield corrupted results.

Changes:

  • Renames the exact-dispatch helper to AllValueTypesMatchConstraint() and generalizes it to enforce identical value argument DataTypes.
  • Applies the same exact-match constraint across all case_when value kernels (primitive, binary, fixed-size binary, decimals, and nested).
  • Adds regression tests covering exact-dispatch matching/failing for parameterized types and runtime failures for mismatched parameterized value types.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cpp/src/arrow/compute/kernels/scalar_if_else.cc Enforces identical concrete value DataTypes via a shared match constraint for all case_when kernels to prevent unsafe exact dispatch.
cpp/src/arrow/compute/kernels/scalar_if_else_test.cc Adds coverage ensuring parameterized types only exact-match when identical and that mismatched cases fail as expected.

@zanmato1984
zanmato1984 force-pushed the codex/case-when-parameterized-exact-dispatch branch from ca07100 to 991fb5d Compare July 24, 2026 01:28
Copilot AI review requested due to automatic review settings July 24, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@zanmato1984
zanmato1984 force-pushed the codex/case-when-parameterized-exact-dispatch branch from 991fb5d to 463e5e4 Compare July 24, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Awaiting review Component: C++ Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Compute] case_when can accept incompatible parameterized value types and return corrupted results

2 participants