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

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

commit 6fa2c6c5ecba491c88dc2d9d72db740926ea364f
Author: Mryange <[email protected]>
AuthorDate: Wed Apr 17 14:32:19 2024 +0800

     [feature](windows function)Improve error handling for window functions 
(#33673)
---
 .../nereids/rules/analysis/CheckAfterRewrite.java  |  3 +-
 .../test_window_function_error.groovy              | 47 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
index 92052bc85ed..40a59697514 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
@@ -35,6 +35,7 @@ import 
org.apache.doris.nereids.trees.expressions.WindowExpression;
 import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
 import 
org.apache.doris.nereids.trees.expressions.functions.generator.TableGeneratingFunction;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction;
+import 
org.apache.doris.nereids.trees.expressions.functions.window.WindowFunction;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.algebra.Generate;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
@@ -85,7 +86,7 @@ public class CheckAfterRewrite extends OneAnalysisRuleFactory 
{
                     throw new AnalysisException("aggregate function is not 
allowed in " + plan.getType());
                 } else if (!isAgg && expr instanceof GroupingScalarFunction) {
                     throw new AnalysisException("grouping scalar function is 
not allowed in " + plan.getType());
-                } else if (!isWindow && expr instanceof WindowExpression) {
+                } else if (!isWindow && (expr instanceof WindowExpression || 
expr instanceof WindowFunction)) {
                     throw new AnalysisException("analytic function is not 
allowed in " + plan.getType());
                 }
             });
diff --git 
a/regression-test/suites/correctness_p0/test_window_function_error.groovy 
b/regression-test/suites/correctness_p0/test_window_function_error.groovy
new file mode 100644
index 00000000000..2a2efc6bdf8
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_window_function_error.groovy
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_window_function_error") {
+    sql """ set enable_nereids_planner = true; """
+    sql """ set enable_fallback_to_original_planner = false; """
+  
+
+    sql """ DROP TABLE IF EXISTS win_func_error_db """
+    sql """
+         CREATE TABLE IF NOT EXISTS win_func_error_db (
+              `k1` INT(11) NOT NULL  COMMENT "",
+              `k2` INT(11) NOT NULL   COMMENT ""
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`k1`)
+            DISTRIBUTED BY HASH(`k1`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+        );
+    """
+
+    sql """
+        insert into win_func_error_db values(1,0);
+    """
+
+    test {
+        sql """
+            select lag(k1,1,0) from win_func_error_db;
+        """
+        exception("analytic function is not allowed in LOGICAL_PROJECT")
+    }
+}


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

Reply via email to