Skip to content

[CALCITE-7450] ValuesReduceRule incorrectly drops tuples when filter condition is irreducible#4846

Open
darpan-e6 wants to merge 1 commit intoapache:mainfrom
darpan-e6:CALCITE-7450
Open

[CALCITE-7450] ValuesReduceRule incorrectly drops tuples when filter condition is irreducible#4846
darpan-e6 wants to merge 1 commit intoapache:mainfrom
darpan-e6:CALCITE-7450

Conversation

@darpan-e6
Copy link

@darpan-e6 darpan-e6 commented Mar 25, 2026

Summary

  • When a filter condition on VALUES contains a UDF with no Janino CallImplementor, RexExecutorImpl cannot reduce it to a RexLiteral and returns the expression unchanged.
  • ValuesReduceRule.apply() then calls isAlwaysTrue() on the unreduced RexCall, which returns false, causing the rule to incorrectly drop the tuple.
  • The fix checks whether the reduced value is a RexLiteral before evaluating isAlwaysTrue(); if it is not reducible, the rule bails out and leaves the plan unchanged.

Test plan

  • Added ValuesReduceRuleTest with a UDF (CUSTOM_FUNC) that cannot be reduced by Janino.
  • The test verifies the plan is unchanged after applying PROJECT_FILTER_VALUES_MERGE — tuples are preserved.

…condition is irreducible

When the filter condition contains a UDF that cannot be reduced to a
RexLiteral (e.g., no Janino CallImplementor), isAlwaysTrue() returns
false for the unreduced RexCall, causing the rule to incorrectly drop
the tuple. The fix checks whether the reduced value is a RexLiteral
before evaluating isAlwaysTrue(); if it is not, the rule bails out
and leaves the plan unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant