Skip to content

[X-3173] Fix union equivalence schema rewrite with stale constants#66

Open
xudong963 wants to merge 1 commit into
branch-53from
xudong963/fix-union-equivalence-projection-panic
Open

[X-3173] Fix union equivalence schema rewrite with stale constants#66
xudong963 wants to merge 1 commit into
branch-53from
xudong963/fix-union-equivalence-projection-panic

Conversation

@xudong963

@xudong963 xudong963 commented Jul 7, 2026

Copy link
Copy Markdown

Which issue does this PR close?

  • Closes #.

Rationale for this change

UnionExec::try_new can panic while computing equivalence properties if stale constant metadata is carried across a projection and then rewritten to the union output schema.

In the observed shape, a filter such as ticker = 'ESU6' can leave a uniform string constant in equivalence properties. After a parent projection drops ticker, union property schema rewriting can see the remaining column slot as a timestamp column and attempt to cast 'ESU6' to Timestamp, which fails during planning.

Equivalence constants are optimizer metadata, so an unrepresentable constant after schema rewrite should be discarded rather than failing query planning.

What changes are included in this PR?

  • Drops a uniform constant during EquivalenceProperties::with_new_schema if its value cannot be cast to the rewritten expression type.
  • Removes trivial equivalence classes after dropping such constants.
  • Propagates UnionExec::compute_properties errors from UnionExec::try_new instead of unwrapping.
  • Adds a regression test for union equivalence schema rewrite with an unrepresentable stale constant value.

Are these changes tested?

Yes:

  • cargo test -p datafusion-physical-expr test_union_drops_unrepresentable_constant_value_after_schema_rewrite
  • cargo test -p datafusion-physical-plan union::tests::test_union
  • cargo test -p datafusion-physical-expr equivalence::properties::union::tests
  • cargo clippy -p datafusion-physical-expr -p datafusion-physical-plan --all-targets -- -D warnings

Are there any user-facing changes?

No API change. This prevents a planner panic for affected UNION ALL + filter + projection query shapes.

@xudong963
xudong963 force-pushed the xudong963/fix-union-equivalence-projection-panic branch from d52626b to 43e932d Compare July 7, 2026 03:34
@xudong963
xudong963 force-pushed the xudong963/fix-union-equivalence-projection-panic branch from 43e932d to 8811a5a Compare July 7, 2026 04:10
@xudong963
xudong963 force-pushed the xudong963/fix-union-equivalence-projection-panic branch from 8811a5a to 39610c6 Compare July 7, 2026 04:33
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.

1 participant