This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new c7ad1f3d212 [fix](Nereids) simplify window expression should inherit data type (#37061) (#37283) c7ad1f3d212 is described below commit c7ad1f3d21286850987e88a7439be4feb058920b Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Thu Jul 4 19:19:05 2024 +0800 [fix](Nereids) simplify window expression should inherit data type (#37061) (#37283) pick from master #37061 after window expression rewritten by literal. literal's data type should same with original window expression. --- .../doris/nereids/rules/rewrite/SimplifyWindowExpression.java | 4 +++- .../simplify_window_expression/simplify_window_expression.out | 8 ++++++++ .../simplify_window_expression/simplify_window_expression.groovy | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SimplifyWindowExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SimplifyWindowExpression.java index 3c59657919e..54979e6f316 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SimplifyWindowExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SimplifyWindowExpression.java @@ -22,6 +22,7 @@ import org.apache.doris.nereids.pattern.MatchingContext; import org.apache.doris.nereids.rules.Rule; import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Slot; @@ -91,7 +92,8 @@ public class SimplifyWindowExpression extends OneRewriteRuleFactory { String name = ((BoundFunction) function).getName(); if ((name.equals(COUNT) && checkCount((Count) boundFunction)) || REWRRITE_TO_CONST_WINDOW_FUNCTIONS.contains(name)) { - projectionsBuilder.add(new Alias(alias.getExprId(), new TinyIntLiteral((byte) 1), alias.getName())); + projectionsBuilder.add(new Alias(alias.getExprId(), + new Cast(new TinyIntLiteral((byte) 1), function.getDataType()), alias.getName())); } else if (REWRRITE_TO_SLOT_WINDOW_FUNCTIONS.contains(name)) { projectionsBuilder.add(new Alias(alias.getExprId(), TypeCoercionUtils.castIfNotSameType(boundFunction.child(0), boundFunction.getDataType()), diff --git a/regression-test/data/nereids_rules_p0/simplify_window_expression/simplify_window_expression.out b/regression-test/data/nereids_rules_p0/simplify_window_expression/simplify_window_expression.out index e660cd7702c..7c72e1c31e7 100644 --- a/regression-test/data/nereids_rules_p0/simplify_window_expression/simplify_window_expression.out +++ b/regression-test/data/nereids_rules_p0/simplify_window_expression/simplify_window_expression.out @@ -265,3 +265,11 @@ PhysicalResultSink ----------filter((mal_test_simplify_window.__DORIS_DELETE_SIGN__ = 0)) ------------PhysicalOlapScan[mal_test_simplify_window] +-- !check_output_type -- +\N 1 1 +1 1 1 +2 1 1 +3 1 1 +4 1 1 +6 1 1 + diff --git a/regression-test/suites/nereids_rules_p0/simplify_window_expression/simplify_window_expression.groovy b/regression-test/suites/nereids_rules_p0/simplify_window_expression/simplify_window_expression.groovy index 3e247b2a78f..840c19846ba 100644 --- a/regression-test/suites/nereids_rules_p0/simplify_window_expression/simplify_window_expression.groovy +++ b/regression-test/suites/nereids_rules_p0/simplify_window_expression/simplify_window_expression.groovy @@ -18,6 +18,7 @@ suite("simplify_window_expression") { sql "SET enable_nereids_planner=true" sql "SET enable_fallback_to_original_planner=false" + sql """ DROP TABLE IF EXISTS mal_test_simplify_window """ @@ -110,4 +111,9 @@ suite("simplify_window_expression") { select a, rank() over (partition by a order by sum(b) desc) as ranking from mal_test_simplify_window group by a; """ + + order_qt_check_output_type """ + select * from ( select a, rank() over (partition by a order by sum(b) desc) as ranking + from mal_test_simplify_window group by a) t, (select 1 a) t2 where t.ranking = t2.a + """ } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org