Skip to content

fix: downcast to FixedSizeBinaryArray in CASE bytes lookup table - #26151

Open
jdymitarai wants to merge 1 commit into
apache:mainfrom
jdymitarai:fix-case-fixedsizebinary
Open

jdymitarai wants to merge 1 commit into
apache:mainfrom
jdymitarai:fix-case-fixedsizebinary

Conversation

@jdymitarai

Copy link
Copy Markdown

Which issue does this PR close?

Closes #26012.

Rationale for this change

When evaluating CASE <expr> WHEN <literal> ... with two or more literal branches of byte-like types, DataFusion optimizes branch evaluation using LiteralLookupTable backed by BytesLikeIndexMap.

In try_get_bytes_iterator, the match arm for DataType::FixedSizeBinary(_) was accidentally calling array.as_binary::<i64>().into_iter(), which attempts to downcast to GenericBinaryArray<i64> (LargeBinaryArray). When presented with a FixedSizeBinaryArray, Arrow's downcast fails and panics:

thread 'main' panicked at arrow-array-60.0.0/src/cast.rs:938:29: binary array

Note that the dictionary arm in the same file (get_bytes_iterator_for_dictionary) already used .downcast_dict::<FixedSizeBinaryArray>(), confirming this was an oversight in the flat array branch.

What changes are included in this PR?

  • Correct the downcast in try_get_bytes_iterator for DataType::FixedSizeBinary(_) to use array.as_fixed_size_binary().into_iter().
  • Add unit tests in datafusion/physical-expr/src/expressions/case.rs covering both FixedSizeBinary and dictionary-encoded Dictionary(UInt8, FixedSizeBinary) CASE evaluation.
  • Add regression tests in datafusion/sqllogictest/test_files/case.slt reproducing the issue query and verifying matching/non-matching branches.

Are these changes tested?

Yes:

  • Added unit tests case_with_expr_fixed_size_binary and case_with_expr_fixed_size_binary_dictionary in datafusion-physical-expr.
  • Added end-to-end regression tests in case.slt.
  • Verified all new and existing tests pass cleanly with cargo test and sqllogictest.

Are there any user-facing changes?

No API changes. Fixes a panic when evaluating CASE expressions with FixedSizeBinary literal branches.

In BytesLikeIndexMap, DataType::FixedSizeBinary was mistakenly downcasting using �rray.as_binary::<i64>() rather than �rray.as_fixed_size_binary(). When a CASE expression with multiple FixedSizeBinary literal WHEN clauses was evaluated via LiteralLookupTable, this triggered a panic in �rrow-array during cast.

Closes apache#26012.
@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CASE with two or more FixedSizeBinary WHEN literals panics

1 participant