Skip to content

Commit

Permalink
[Fix](Nereids) fix fe fold constant evaluate like function (#37616)
Browse files Browse the repository at this point in the history
Problem:
When evaluating like function using fe, it can not evaluating
nullliteral correctly
Example:
Null like "%string%"   can not folded to null on fe
Reason:
Fe fold constant does not deal with like function
Solved:
Add fe fold constant of like function
  • Loading branch information
LiBinfeng-01 authored Jul 15, 2024
1 parent ad3e4d5 commit 420c849
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.doris.nereids.trees.expressions.IsNull;
import org.apache.doris.nereids.trees.expressions.LessThan;
import org.apache.doris.nereids.trees.expressions.LessThanEqual;
import org.apache.doris.nereids.trees.expressions.Like;
import org.apache.doris.nereids.trees.expressions.Not;
import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
import org.apache.doris.nereids.trees.expressions.Or;
Expand Down Expand Up @@ -403,11 +402,6 @@ public Expression visitOr(Or or, ExpressionRewriteContext context) {
}
}

@Override
public Expression visitLike(Like like, ExpressionRewriteContext context) {
return like;
}

@Override
public Expression visitCast(Cast cast, ExpressionRewriteContext context) {
cast = rewriteChildren(cast, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ suite("test_fold_constant_by_fe") {
sql 'set enable_nereids_planner=true'
sql 'set enable_fallback_to_original_planner=false'
sql 'set enable_fold_nondeterministic_fn=true'
sql 'set enable_fold_constant_by_be=false'

def results = sql 'select uuid(), uuid()'
assertFalse(Objects.equals(results[0][0], results[0][1]))
Expand Down Expand Up @@ -154,4 +155,12 @@ suite("test_fold_constant_by_fe") {
res = res.split('VUNION')[1]
assertFalse(res.contains("unix"))
}
}

// test null like string cause of fe need to fold constant like that to enable not null derive
res = sql """explain select null like '%123%'"""
assertFalse(res.contains("like"))
// now fe fold constant still can not deal with this case
res = sql """explain select "12" like '%123%'"""
assertTrue(res.contains("like"))

}

0 comments on commit 420c849

Please sign in to comment.