Skip to content

fix: downcast to FixedSizeBinaryArray in CASE literal lookup table - #26096

Open
patrickswedish wants to merge 1 commit into
apache:mainfrom
patrickswedish:fix/case-fixed-size-binary-lookup-26012
Open

patrickswedish wants to merge 1 commit into
apache:mainfrom
patrickswedish:fix/case-fixed-size-binary-lookup-26012

Conversation

@patrickswedish

@patrickswedish patrickswedish commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #26012.

Rationale for this change

In LiteralLookupTable, evaluation of CASE <expr> WHEN <literal> ... with byte-like literals delegates to BytesLikeIndexMap. In try_get_bytes_iterator, the DataType::FixedSizeBinary(_) match arm erroneously attempted to downcast the array via as_binary::<i64>() (inherited from DataType::LargeBinary), rather than handling FixedSizeBinaryArray.

When a query contained 2 or more FixedSizeBinary WHEN literals, LiteralLookupTable was constructed and panicked during evaluation when downcasting to GenericBinaryArray<i64>:

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

What changes are included in this PR?

  1. Fix Downcast in Lookup Table: Updated DataType::FixedSizeBinary(_) arm in try_get_bytes_iterator (bytes_like_lookup_table.rs) to downcast via array.as_fixed_size_binary().iter(), matching the dictionary downcasting path and returning byte slices correctly.
  2. Unit Test: Added test_case_when_literal_lookup_fixed_size_binary_to_int32 in datafusion/physical-expr/src/expressions/case.rs testing LiteralLookupTable evaluation with FixedSizeBinary literals with and without ELSE, with and without NULLs.
  3. Sqllogictest: Added regression tests in datafusion/sqllogictest/test_files/case.slt verifying FixedSizeBinary CASE evaluation against branch 1, branch 2, fallback, NULL inputs, and multiple rows.

Are these changes tested?

Yes:

  • Unit test in datafusion/physical-expr/src/expressions/case.rs (test_case_when_literal_lookup_fixed_size_binary_to_int32)
  • Sqllogictest in datafusion/sqllogictest/test_files/case.slt
  • Validated locally with cargo test and cargo clippy.

Are there any user-facing changes?

Bug fix: queries with CASE expressions containing multiple FixedSizeBinary literals now evaluate correctly instead of panicking.

Fixes apache#26012.

In LiteralLookupTable, evaluation of CASE <expr> WHEN <literal> ...
with byte-like literals delegates to BytesLikeIndexMap. In
	ry_get_bytes_iterator, the DataType::FixedSizeBinary(_) match arm
erroneously attempted to downcast the array via �s_binary::<i64>()
(inherited from DataType::LargeBinary), rather than handling
FixedSizeBinaryArray.

When a query contained 2 or more FixedSizeBinary WHEN literals,
LiteralLookupTable was constructed and panicked during evaluation
when downcasting to GenericBinaryArray<i64> with �inary array.

This fix updates DataType::FixedSizeBinary(_) in
	ry_get_bytes_iterator to downcast via �rray.as_fixed_size_binary().iter(),
matching the dictionary downcasting path and enabling correct evaluation.

Signed-off-by: Patrick Ribbsaeter <patrickswedish@users.noreply.github.com>
@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Oct 7, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.72%. Comparing base (db83fcc) to head (bc969b0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26096      +/-   ##
==========================================
- Coverage   82.72%   82.72%   -0.01%     
==========================================
  Files        1147     1147              
  Lines      448179   448214      +35     
  Branches   448179   448214      +35     
==========================================
+ Hits       370754   370778      +24     
- Misses      54895    54903       +8     
- Partials    22530    22533       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

2 participants