Skip to content

[CALCITE-7635] Simplification result of conjunction of comparisons depends on terms order#5070

Open
rubenada wants to merge 2 commits into
apache:mainfrom
rubenada:CALCITE-7635
Open

[CALCITE-7635] Simplification result of conjunction of comparisons depends on terms order#5070
rubenada wants to merge 2 commits into
apache:mainfrom
rubenada:CALCITE-7635

Conversation

@rubenada

@rubenada rubenada commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7635

Changes Proposed

Return IS NOT NULL in RexSimplify#simplifyUsingPredicates (when ranges are satisfied considered previous predicates) only if unknownAs is UNKNOWN (otherwise simply return TRUE).
See more details in Jira.

// Range is always satisfied given these predicates; but nullability might
// be problematic
if (unknownAs != UNKNOWN) {
// If unknownAs FALSE: row is already excluded for null input, so the IS_NOT_NULL

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.

do your tests cover all 3 cases here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new test covering 3 cases

// E.g. given predicate "x >= 5" and term "x between 3 and 10"
// we weaken to term to "x between 5 and 10".
final RexNode term2 = simplifyUsingPredicates(term, clazz);
final RexNode term2 = simplifyUsingPredicates(term, clazz, FALSE);

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.

Can you argue why FALSE is always correct here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is called simplifyAnd2ForUnknownAsFalse, and the javadoc (on the overloaded method) states "... we assume that if the expression returns UNKNOWN it will be interpreted as FALSE". There are other cases in this method were we need to call another one passing a RexUnknownAs parameter, and FALSE value is used (e.g. return simplify(terms.get(0), FALSE) in line 1873)

@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

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.

2 participants