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

dataroaring 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 1abfa4f270f [Bug](materialized-view)  check duplicate expr when create 
mv stmt not have groupby exprs  (#49595)
1abfa4f270f is described below

commit 1abfa4f270f89a30e30dc1f6d60ad33153f6d515
Author: Pxl <x...@selectdb.com>
AuthorDate: Mon Mar 31 15:55:04 2025 +0800

    [Bug](materialized-view)  check duplicate expr when create mv stmt not have 
groupby exprs  (#49595)
    
    ### What problem does this PR solve?
    check duplicate expr when create mv stmt not have groupby exprs
    ### Check List (For Author)
---
 .../doris/analysis/CreateMaterializedViewStmt.java  | 21 +++++++++++----------
 regression-test/suites/mv_p0/unique/unique.groovy   |  5 +++++
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index f4ff1f80b5e..166ee53276b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -349,13 +349,23 @@ public class CreateMaterializedViewStmt extends DdlStmt 
implements NotFallbackIn
         if (selectStmt.getGroupByClause() == null && mvKeysType == 
KeysType.AGG_KEYS) {
             throw new AnalysisException("agg mv must has group by clause");
         }
+
+        List<Expr> selectExprs = selectStmt.getSelectList().getExprs();
+        Set<String> selectExprNames = 
Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
+        for (Expr expr : selectExprs) {
+            String selectExprName = 
selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
+            if (selectExprNames.contains(selectExprName)) {
+                throw new AnalysisException("The select expr " + 
selectExprName + " is duplicated.");
+            }
+            selectExprNames.add(selectExprName);
+        }
+
         if (selectStmt.getGroupByClause() == null) {
             return;
         }
 
         List<Expr> groupingExprs = 
selectStmt.getGroupByClause().getGroupingExprs();
         List<FunctionCallExpr> aggregateExprs = 
selectStmt.getAggInfo().getAggregateExprs();
-        List<Expr> selectExprs = selectStmt.getSelectList().getExprs();
         for (Expr expr : selectExprs) {
             boolean match = false;
             String lhs = 
selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
@@ -381,15 +391,6 @@ public class CreateMaterializedViewStmt extends DdlStmt 
implements NotFallbackIn
             }
         }
 
-        Set<String> selectExprNames = 
Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
-        for (Expr expr : selectExprs) {
-            String selectExprName = 
selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
-            if (selectExprNames.contains(selectExprName)) {
-                throw new AnalysisException("The select expr " + 
selectExprName + " is duplicated.");
-            }
-            selectExprNames.add(selectExprName);
-        }
-
         for (Expr expr : groupingExprs) {
             String groupExprName = 
selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
             if (!selectExprNames.contains(groupExprName)) {
diff --git a/regression-test/suites/mv_p0/unique/unique.groovy 
b/regression-test/suites/mv_p0/unique/unique.groovy
index d054803678d..66170697d34 100644
--- a/regression-test/suites/mv_p0/unique/unique.groovy
+++ b/regression-test/suites/mv_p0/unique/unique.groovy
@@ -52,6 +52,11 @@ suite ("unique") {
         exception "The materialized view not support value column before key 
column"
     }
 
+    test {
+        sql """create materialized view kadj as select k3,k2,k1,k4,k4 from 
u_table;"""
+        exception "is duplicated"
+    }
+
     createMV("create materialized view kadj as select k3,k2,k1,k4 from 
u_table;")
 
     createMV("create materialized view kadj2 as select k1,k3,k2,length(k4) 
from u_table;")


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

Reply via email to