morrySnow commented on code in PR #49457:
URL: https://github.com/apache/doris/pull/49457#discussion_r2021297589
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/ExpressionRewriteSqlTest.java:
##########
@@ -44,4 +43,44 @@ public void testExtractNonConstant() {
"OR[id#0 IN (10, 20, 30, 300),(id#0 =
score#1),(id#0 = (score#1 + 10)),(id#0 = (score#1 + score#1))]"
)));
}
+
+ @Test
+ public void testSimplifyRangeAndExtractCommonFactor() {
+ String sql = "select * from T1 where id > 1 and score > 1 or id > 1
and score > 10";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .matches(
+ logicalFilter().when(f ->
f.getPredicate().toString().equals(
+ "AND[(id#0 > 1),(score#1 > 1)]"
+ )));
+
+ sql = "select * from T1 where id > 1 and score > 1 or id > 1 and id <
0";
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .matches(
+ logicalFilter().when(f ->
f.getPredicate().toString().equals(
+ "AND[(score#1 > 1),(id#0 > 1)]"
Review Comment:
check with toString is not a good idea, maybe `toSql` or a new util function
`equalsWithoutExprId` is better
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateFilter.java:
##########
@@ -49,7 +50,14 @@ public List<Rule> buildRules() {
.thenApply(ctx -> {
LogicalFilter<Plan> filter = ctx.root;
ImmutableSet.Builder<Expression> newConjuncts =
ImmutableSet.builder();
+ boolean needEliminateNull =
!ctx.cascadesContext.getConnectContext().getSessionVariable()
+ .isDebugSkipFoldConstant();
+ ExpressionRewriteContext context =
+ new ExpressionRewriteContext(ctx.cascadesContext);
for (Expression expression : filter.getConjuncts()) {
+ if (needEliminateNull) {
+ expression =
FoldConstantRule.evaluate(eliminateNullLiteral(expression), context);
Review Comment:
chould we check `isDebugSkipFoldConstant` in `FoldConstantRule.evaluate` and
in `eliminateNullLiteral` directly?
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateFilterTest.java:
##########
@@ -62,6 +69,80 @@ void testEliminateFilterNull() {
.matches(logicalEmptyRelation());
}
+ @Test
+ void testEliminateFilterReduceNull() {
Review Comment:
test `replaceNullToFalse` function directly in UT to ensure it works a
expsectd
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]