Skip to content

[CALCITE-4159] Simplify always-true expressions (such as LIKE '%') to TRUE #2105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

julianhyde
Copy link
Contributor

No description provided.

/** Returns whether this predicate can while simplifying other OR
* operands. */
default boolean allowedInOr(RelOptPredicateList predicates) {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to lack some words between can and while.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. i'll fix.

protected RexNode like(RexNode ref, RexNode pattern, RexNode escape) {
return rexBuilder.makeCall(SqlStdOperatorTable.LIKE, ref, pattern, escape);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

What does this method mean? Could you add some comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree. There are lots of surrounding methods with a similar pattern. They are protected methods in a test case. Javadoc would not add anything.

// is not null.
RexCall call = (RexCall) e;
if (call.getOperands().get(1) instanceof RexLiteral) {
return isEffectivelyNotNull(call.getOperands().get(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

do we also need to consider cases such as '10 > ref' here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed this comment. I'll address during CALCITE-4173.

In RexProgramTest, construct literals when needed, rather than caching in variables.

The word 'comparison' is mis-spelled in a few places.

Deprecate RelReferentialConstraint.getNumColumns().

Change TableFunctionScanFactory argument from RexNode to RexCall.
We can now simplify 'a = 1 or a <> 1' to 'true'. To achieve
this, we simplify the second term in a context where we know
'a = 1' is false. This entails a RangeSet inside
simplifyUsingPredicates, so that we can represent <> the same
way that we represent =, > etc. All of the others are a Range,
but <> requires a two-entry RangeSet ('a < 1 or a > 1').
… TRUE

RexSimplify needs to recognize that the following expressions
can be simplified to TRUE:

* c < 0 OR c >= 0 OR c IS NULL
* c < 2 OR c > 0 OR c IS NULL
* c LIKE '%' OR c IS NULL

To enable this fix, we pull 'IS NULL' terms to the front of a list of
OR-terms, so that by the time the subsequent terms are reached they
know that the term's value is not NULL.
…at represents a set of values or ranges

Obsolete use of IN in RexCall.
@asfgit asfgit closed this in 9ca61f0 Aug 20, 2020
MalteBellmann pushed a commit to caespes/calcite that referenced this pull request Feb 21, 2021
… TRUE

RexSimplify needs to recognize that the following expressions
can be simplified to TRUE:

* c < 0 OR c >= 0 OR c IS NULL
* c < 2 OR c > 0 OR c IS NULL
* c LIKE '%' OR c IS NULL

To enable this fix, we pull 'IS NULL' terms to the front of a list of
OR-terms, so that by the time the subsequent terms are reached they
know that the term's value is not NULL.

Close apache#2105
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.

5 participants