Skip to content

Commit

Permalink
[fix](Nereids) simplify conditional function generate wrong nullable
Browse files Browse the repository at this point in the history
related pr #37613

because adjust nullable do not run after simplify confitional function,
we should not change any output's nullable in this rule
  • Loading branch information
morrySnow committed Nov 18, 2024
1 parent f74610c commit 687d5e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ abc
ab
abc

-- !test_nullable_nullif --
1 1

Original file line number Diff line number Diff line change
Expand Up @@ -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 )"
}

0 comments on commit 687d5e3

Please sign in to comment.