This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new cd70f1984e0 branch-3.0: [fix](nereids) fix ptopN push down under multi 
winexprs with partial forbidden type #44617 (#44649)
cd70f1984e0 is described below

commit cd70f1984e091833ab14c24cc48b3680f20c17ce
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Nov 27 14:15:08 2024 +0800

    branch-3.0: [fix](nereids) fix ptopN push down under multi winexprs with 
partial forbidden type #44617 (#44649)
    
    Cherry-picked from #44617
    
    Co-authored-by: xzj7019 <xiongzhongj...@selectdb.com>
---
 .../nereids/trees/plans/logical/LogicalWindow.java | 10 +++---
 .../data/nereids_syntax_p0/window_function.out     |  6 ++++
 .../push_down_multi_filter_through_window.groovy   | 20 +++++++++++
 .../nereids_syntax_p0/window_function.groovy       | 39 ++++++++++++++++++++++
 4 files changed, 70 insertions(+), 5 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java
index 6cd8389349a..5ee70afbf5f 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java
@@ -218,7 +218,7 @@ public class LogicalWindow<CHILD_TYPE extends Plan> extends 
LogicalUnary<CHILD_T
         for (NamedExpression windowExpr : windowExpressions) {
             if (windowExpr == null || windowExpr.children().size() != 1
                     || !(windowExpr.child(0) instanceof WindowExpression)) {
-                continue;
+                return null;
             }
             WindowExpression windowFunc = (WindowExpression) 
windowExpr.child(0);
 
@@ -226,12 +226,12 @@ public class LogicalWindow<CHILD_TYPE extends Plan> 
extends LogicalUnary<CHILD_T
             if (!(windowFunc.getFunction() instanceof RowNumber
                     || windowFunc.getFunction() instanceof Rank
                     || windowFunc.getFunction() instanceof DenseRank)) {
-                continue;
+                return null;
             }
 
             // Check the partition key and order key.
             if (windowFunc.getPartitionKeys().isEmpty() && 
windowFunc.getOrderKeys().isEmpty()) {
-                continue;
+                return null;
             }
 
             // Check the window type and window frame.
@@ -240,10 +240,10 @@ public class LogicalWindow<CHILD_TYPE extends Plan> 
extends LogicalUnary<CHILD_T
                 WindowFrame frame = windowFrame.get();
                 if (!(frame.getLeftBoundary().getFrameBoundType() == 
WindowFrame.FrameBoundType.UNBOUNDED_PRECEDING
                         && frame.getRightBoundary().getFrameBoundType() == 
WindowFrame.FrameBoundType.CURRENT_ROW)) {
-                    continue;
+                    return null;
                 }
             } else {
-                continue;
+                return null;
             }
 
             // Check filter conditions.
diff --git a/regression-test/data/nereids_syntax_p0/window_function.out 
b/regression-test/data/nereids_syntax_p0/window_function.out
index 4ec92fc61ad..38eba68274e 100644
--- a/regression-test/data/nereids_syntax_p0/window_function.out
+++ b/regression-test/data/nereids_syntax_p0/window_function.out
@@ -561,3 +561,9 @@
 \N
 \N
 
+-- !multi_winf1 --
+1      c
+
+-- !multi_winf2 --
+1      35
+
diff --git 
a/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy
 
b/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy
index d808d30f8eb..015a6e7fae7 100644
--- 
a/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy
+++ 
b/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy
@@ -157,4 +157,24 @@ suite("push_down_multi_filter_through_window") {
         sql ("select * from (select row_number() over(partition by c1, c2 
order by c3) as rn, rank() over(partition by c1 order by c3) as rk from 
push_down_multi_predicate_through_window_t) t where rn <= 1 or rk <= 1;")
         notContains "VPartitionTopN"
     }
+
+    explain {
+        sql ("select * from (select row_number() over(partition by c1, c2 
order by c3) as rn, sum(c2) over(order by c2 range between unbounded preceding 
and unbounded following) as sw from push_down_multi_predicate_through_window_t) 
t where rn <= 1 and sw <= 1;")
+        notContains "VPartitionTopN"
+    }
+
+    explain {
+        sql ("select * from (select sum(c2) over(order by c2 range between 
unbounded preceding and unbounded following) as sw, row_number() over(partition 
by c1, c2 order by c3) as rn from push_down_multi_predicate_through_window_t) t 
where rn <= 1 and sw <= 1;")
+        notContains "VPartitionTopN"
+    }
+
+    explain {
+        sql ("select * from (select row_number() over(partition by c1, c2 
order by c3 rows between unbounded preceding and current row) as rn, sum(c2) 
over(order by c2) as sw from push_down_multi_predicate_through_window_t) t 
where rn <= 1 and sw <= 1;")
+        notContains "VPartitionTopN"
+    }
+
+    explain {
+        sql ("select * from (select sum(c2) over(order by c2) as sw, 
row_number() over(partition by c1, c2 order by c3  rows between unbounded 
preceding and current row) as rn from 
push_down_multi_predicate_through_window_t) t where rn <= 1 and sw <= 1;")
+        notContains "VPartitionTopN"
+    }
 }
diff --git a/regression-test/suites/nereids_syntax_p0/window_function.groovy 
b/regression-test/suites/nereids_syntax_p0/window_function.groovy
index 9a427d10198..31cb425fcf7 100644
--- a/regression-test/suites/nereids_syntax_p0/window_function.groovy
+++ b/regression-test/suites/nereids_syntax_p0/window_function.groovy
@@ -240,4 +240,43 @@ suite("window_function") {
     """
 
     qt_sql """ select LAST_VALUE(col_tinyint_undef_signed_not_null) over 
(partition by col_double_undef_signed_not_null, col_int_undef_signed, 
(col_float_undef_signed_not_null - col_int_undef_signed), 
round_bankers(col_int_undef_signed) order by pk rows between unbounded 
preceding and 4 preceding) AS col_alias56089 from 
table_200_undef_partitions2_keys3_properties4_distributed_by53 order by 
col_alias56089;  """
+
+    order_qt_multi_winf1 """
+        select *
+            from (
+                select
+                row_number() over(partition by c1 order by c2) rn,
+                lead(c2, 2, '') over(partition by c1 order by c2)
+                from (
+                  select 1 as c1, 'a' as c2
+                  union all
+                  select 1 as c1, 'b' as c2
+                  union all
+                  select 1 as c1, 'c' as c2
+                  union all
+                  select 1 as c1, 'd' as c2
+                  union all
+                  select 1 as c1, 'e' as c2
+                )t
+            )a where rn=1
+    """
+    order_qt_multi_winf2 """
+        select *
+            from (
+                select
+                row_number() over(partition by c1 order by c2) rn,
+                sum(c2) over(order by c2 range between unbounded preceding and 
unbounded following)
+                from (
+                  select 1 as c1, 5 as c2
+                  union all
+                  select 1 as c1, 6 as c2
+                  union all
+                  select 1 as c1, 7 as c2
+                  union all
+                  select 1 as c1, 8 as c2
+                  union all
+                  select 1 as c1, 9 as c2
+                )t
+            )a where rn=1
+    """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to