diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyConditionalFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyConditionalFunction.java index 359cb887fe54b76..c1c6283e32d21c7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyConditionalFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyConditionalFunction.java @@ -22,6 +22,7 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.scalar.Coalesce; import org.apache.doris.nereids.trees.expressions.functions.scalar.NullIf; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Nullable; import org.apache.doris.nereids.trees.expressions.functions.scalar.Nvl; import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; @@ -98,7 +99,7 @@ private static Expression rewriteNvl(Nvl nvl) { */ private static Expression rewriteNullIf(NullIf nullIf) { if (nullIf.child(0) instanceof NullLiteral || nullIf.child(1) instanceof NullLiteral) { - return nullIf.child(0); + return new Nullable(nullIf.child(0)); } else { return nullIf; } diff --git a/regression-test/data/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.out b/regression-test/data/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.out index 91f9110804b8b6f..d9f4f3b335872c3 100644 --- a/regression-test/data/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.out +++ b/regression-test/data/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.out @@ -131,3 +131,6 @@ abc ab abc +-- !test_nullable_nullif -- +1 1 + diff --git a/regression-test/suites/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.groovy b/regression-test/suites/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.groovy index 18443bb152abdab..2b99ad0a23a8a5b 100644 --- a/regression-test/suites/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.groovy +++ b/regression-test/suites/nereids_rules_p0/simplify_conditional_function/simplify_conditional_function.groovy @@ -49,4 +49,6 @@ suite("simplify_conditional_function") { qt_test_outer_ref_coalesce "select c1 from (select coalesce(null,a,c) c1,a,b from test_simplify_conditional_function order by c1,a,b limit 2) t group by c1 order by c1" qt_test_outer_ref_nvl "select c1 from (select ifnull(null, c) c1 from test_simplify_conditional_function order by 1 limit 2) t group by c1 order by c1" qt_test_outer_ref_nullif "select c1 from (select nullif(a, null) c1,c from test_simplify_conditional_function order by c1,c limit 2 ) t group by c1 order by c1" + + qt_test_nullable_nullif "SELECT COUNT( DISTINCT NULLIF ( 1, NULL ) ), COUNT( DISTINCT 72 )" } \ No newline at end of file