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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 3163127510b [fix](planner)remove constant expr in window function's 
partition and order exprs (#36186)
3163127510b is described below

commit 3163127510b35dff921638c41d52d28a50f274a8
Author: starocean999 <[email protected]>
AuthorDate: Thu Jun 13 09:34:07 2024 +0800

    [fix](planner)remove constant expr in window function's partition and order 
exprs (#36186)
    
    pick from master https://github.com/apache/doris/pull/36184
---
 .../java/org/apache/doris/analysis/AnalyticExpr.java   | 18 ++----------------
 .../window_functions/test_window_function.out          | 18 ++++++++++++++++++
 .../window_functions/test_window_function.groovy       |  3 +++
 3 files changed, 23 insertions(+), 16 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java
index 2a9e9a9c88d..e24ff74e9d2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java
@@ -463,22 +463,8 @@ public class AnalyticExpr extends Expr {
     public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
         fnCall.analyze(analyzer);
         type = getFnCall().getType();
-
-        for (Expr e : partitionExprs) {
-            if (e.isLiteral()) {
-                throw new AnalysisException(
-                    "Expressions in the PARTITION BY clause must not be 
constant: "
-                    + e.toSql() + " (in " + toSql() + ")");
-            }
-        }
-
-        for (OrderByElement e : orderByElements) {
-            if (e.getExpr().isLiteral()) {
-                throw new AnalysisException(
-                    "Expressions in the ORDER BY clause must not be constant: "
-                            + e.getExpr().toSql() + " (in " + toSql() + ")");
-            }
-        }
+        partitionExprs.removeIf(expr -> expr.isConstant());
+        orderByElements.removeIf(expr -> expr.getExpr().isConstant());
 
         if (getFnCall().getParams().isDistinct()) {
             throw new AnalysisException(
diff --git 
a/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
 
b/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
index 8a753341bbd..5d5231297a6 100644
--- 
a/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
@@ -574,3 +574,21 @@ USA        Pete    Hello
 32767  6       12      32767
 32767  6       6       32767
 
+-- !sql --
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+
diff --git 
a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
index eb5d557469b..76bffcbb7b1 100644
--- 
a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
@@ -492,5 +492,8 @@ suite("test_window_function") {
            ( SELECT k2, k1, row_number () over (PARTITION BY k2 ORDER BY k3) 
AS wj  
            FROM baseall ) AS A JOIN ( SELECT k2, k1, row_number () over  
            (PARTITION BY k2 ORDER BY k3) AS wj FROM baseall ) AS B WHERE 
A.k2=B.k2"""
+
+    sql """set enable_nereids_planner=false"""
+    qt_sql """SELECT row_number() OVER (partition by 1 order by 2) from 
baseall order by 1; """
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to