Skip to content

Fix CASE evaluation for custom column expressions - #24484

Open
Hasnaathussain wants to merge 1 commit into
apache:mainfrom
Hasnaathussain:fix/21231-case-custom-column-projection
Open

Fix CASE evaluation for custom column expressions#24484
Hasnaathussain wants to merge 1 commit into
apache:mainfrom
Hasnaathussain:fix/21231-case-custom-column-projection

Conversation

@Hasnaathussain

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

A custom column-like PhysicalExpr can read an input column without downcasting to DataFusion's concrete Column type. CASE's internal projection then misses that dependency and evaluates the expression against a zero-column batch, causing a runtime error.

What changes are included in this PR?

CASE projection now falls back to the original input batch when it encounters an unknown leaf expression. Known columns, lambda variables, literals, and composite expressions keep the existing projection optimization.

The regression test uses a custom PhysicalExpr that wraps a column without exposing a concrete Column node.

Are these changes tested?

Yes:

  • cargo fmt --all -- --check
  • cargo clippy -p datafusion-physical-expr --all-targets --all-features -- -D warnings
  • cargo test -p datafusion-physical-expr expressions::case::tests (36 passed)
  • cargo test -p datafusion-physical-expr (1,596 passed, 2 ignored; 13 doctests passed)

The extended workspace command also reached the existing TPC-H q15 unparser failure. Its multi-statement error reproduces unchanged at the base commit, outside this patch.

Are there any user-facing changes?

Custom physical expressions can now be evaluated correctly inside searched CASE expressions. There is no public API change.

Signed-off-by: Hasnaat Hussain <hasnaat.hussain.2@gmail.com>
@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label Aug 19, 2026
@Hasnaathussain
Hasnaathussain marked this pull request as ready for review August 19, 2026 08:48
Copilot AI lite review requested due to automatic review settings August 19, 2026 08:48

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CaseWhen does not work with custom implemented column expression

2 participants