vlsi opened a new pull request, #5327: URL: https://github.com/apache/calcite/pull/5327
With `copyFilter` enabled, `FilterProjectTransposeRule` copied the input's distribution by wrapping `getTrait(RelDistributionTraitDef.INSTANCE)` in a singleton list for `RelTraitSet#replaceIfs`. When the Filter's trait set has a distribution trait and the input's has none, `getTrait` returns null, and `RelCompositeTrait.of` throws `java.lang.NullPointerException: Cannot invoke "org.apache.calcite.plan.RelTrait.getClass()" because "trait" is null`. This happens, for example, under a planner that does not register `RelDistributionTraitDef` when a distribution is added to the Filter with `RelTraitSet#plus`. The rule now uses `RelTraitSet#replaceIf`, the same call `LogicalFilter.create` uses for distribution, which falls back to the trait's default when the supplier returns null. With no distribution on the input, the pushed Filter gets `RelDistributions.ANY`, the same fallback the rule already uses for collation. With a distribution on the input, the pushed Filter still takes the input's distribution. `RelOptRulesTest#testFilterProjectTransposeRuleInputWithoutDistribution` (new) fails with the NPE above without the change. `testFilterProjectTransposeRuleInputWithDistribution` (new) passes before and after; it pins the case where the input has a distribution, which the changed line also covers. Found while reviewing CALCITE-7736 (#5213), which carries the same fix inside its nullness migration; once this merges, that PR can drop the hunk. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
