Skip to content

GH-55960: [C++] Raise instead of crashing in if_else with a non-boolean condition and dictionary values - #55962

Open
Chetansahney wants to merge 1 commit into
apache:mainfrom
Chetansahney:GH-55960-if-else-dictionary-condition
Open

Chetansahney wants to merge 1 commit into
apache:mainfrom
Chetansahney:GH-55960-if-else-dictionary-condition

Conversation

@Chetansahney

@Chetansahney Chetansahney commented Dec 4, 2026 •

Copy link
Copy Markdown

Rationale for this change

if_else crashes the process when the condition is not boolean and both values have the same dictionary type:

values = pa.array(["a", "b"]).dictionary_encode()
pc.if_else(pa.array([1, 0]), values, values)

IfElseFunction::DispatchBest sends identical dictionary types to DispatchExactImpl and returns the result after only a DCHECK(kernel). No kernel matches a non-boolean condition, so release builds return a null kernel and then call it.

What changes are included in this PR?

The dictionary branch now returns NoMatchingKernel when DispatchExactImpl finds nothing, which is what the non-dictionary path already does.

Are these changes tested?

Yes. TestIfElse.DictionaryNonBooleanCondition checks the error for an int64 condition with dictionary values, including a null scalar as the second value. It fails without the change. arrow-compute-scalar-if-else-test passes in full (Windows, MSVC, Release).

Are there any user-facing changes?

The call above now raises ArrowNotImplementedError: Function 'if_else' has no kernel matching input types instead of crashing.

This PR contains a "Critical Fix". It fixes a crash (segmentation fault) on user input.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

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.

[C++] if_else crashes with a non-boolean condition and dictionary values

1 participant