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

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


The following commit(s) were added to refs/heads/master by this push:
     new 6ce368783c5 [fix](mtmv)mtmv support default key (#36221)
6ce368783c5 is described below

commit 6ce368783c5c31718d55ffe28be2fbefc8fcee7a
Author: zhangdong <493738...@qq.com>
AuthorDate: Mon Jun 17 11:33:50 2024 +0800

    [fix](mtmv)mtmv support default key (#36221)
    
    When no dup key is specified, it is generated by default
---
 .../trees/plans/commands/info/CreateMTMVInfo.java  | 43 ++++++++++++++++++++++
 regression-test/data/mtmv_p0/test_build_mtmv.out   |  2 +-
 .../suites/mtmv_p0/test_build_mtmv.groovy          |  5 ---
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
index ffacc401e27..c4de4dca35d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
@@ -30,8 +30,10 @@ import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.KeysType;
 import org.apache.doris.catalog.PartitionType;
 import org.apache.doris.catalog.TableIf;
+import org.apache.doris.catalog.Type;
 import org.apache.doris.catalog.View;
 import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.FeConstants;
 import org.apache.doris.common.FeNameFormat;
 import org.apache.doris.common.util.DynamicPartitionUtil;
 import org.apache.doris.common.util.PropertyAnalyzer;
@@ -63,6 +65,7 @@ import 
org.apache.doris.nereids.trees.plans.logical.LogicalSink;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
 import 
org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionCollector;
 import org.apache.doris.nereids.types.AggStateType;
+import org.apache.doris.nereids.types.DataType;
 import org.apache.doris.nereids.util.Utils;
 import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.SessionVariable;
@@ -182,6 +185,7 @@ public class CreateMTMVInfo {
     }
 
     private void analyzeProperties() {
+        properties = 
PropertyAnalyzer.getInstance().rewriteOlapProperties(mvName.getCtl(), 
mvName.getDb(), properties);
         if 
(DynamicPartitionUtil.checkDynamicPartitionPropertiesExist(properties)) {
             throw new AnalysisException("Not support dynamic partition 
properties on async materialized view");
         }
@@ -218,11 +222,50 @@ public class CreateMTMVInfo {
         }
         getRelation(planner);
         getColumns(plan);
+        analyzeKeys();
         this.mvPartitionInfo = mvPartitionDefinition
                 .analyzeAndTransferToMTMVPartitionInfo(planner, ctx, 
logicalQuery);
         this.partitionDesc = generatePartitionDesc(ctx);
     }
 
+    private void analyzeKeys() {
+        boolean enableDuplicateWithoutKeysByDefault = false;
+        try {
+            if (properties != null) {
+                enableDuplicateWithoutKeysByDefault =
+                        
PropertyAnalyzer.analyzeEnableDuplicateWithoutKeysByDefault(properties);
+            }
+        } catch (Exception e) {
+            throw new AnalysisException(e.getMessage(), e.getCause());
+        }
+        if (keys.isEmpty() && !enableDuplicateWithoutKeysByDefault) {
+            keys = Lists.newArrayList();
+            int keyLength = 0;
+            for (ColumnDefinition column : columns) {
+                DataType type = column.getType();
+                Type catalogType = column.getType().toCatalogDataType();
+                keyLength += catalogType.getIndexSize();
+                if (keys.size() >= FeConstants.shortkey_max_column_count
+                        || keyLength > FeConstants.shortkey_maxsize_bytes) {
+                    if (keys.isEmpty() && type.isStringLikeType()) {
+                        keys.add(column.getName());
+                    }
+                    break;
+                }
+                if (type.isFloatLikeType() || type.isStringType() || 
type.isJsonType()
+                        || catalogType.isComplexType() || type.isBitmapType() 
|| type.isHllType()
+                        || type.isQuantileStateType() || type.isJsonType() || 
type.isStructType()
+                        || column.getAggType() != null) {
+                    break;
+                }
+                keys.add(column.getName());
+                if (type.isVarcharType()) {
+                    break;
+                }
+            }
+        }
+    }
+
     private void getRelation(NereidsPlanner planner) {
         // Should not make table without data to empty relation when analyze 
the related table,
         // so add disable rules
diff --git a/regression-test/data/mtmv_p0/test_build_mtmv.out 
b/regression-test/data/mtmv_p0/test_build_mtmv.out
index db69c393748..5e5632511f4 100644
--- a/regression-test/data/mtmv_p0/test_build_mtmv.out
+++ b/regression-test/data/mtmv_p0/test_build_mtmv.out
@@ -61,7 +61,7 @@ zhangsang     200
 11     111
 
 -- !desc_mv --
-field_1        VARCHAR(16)     No      false   \N      NONE
+field_1        VARCHAR(16)     No      true    \N      
 
 -- !query_mv_with_cte --
 2      3
diff --git a/regression-test/suites/mtmv_p0/test_build_mtmv.groovy 
b/regression-test/suites/mtmv_p0/test_build_mtmv.groovy
index 8614272a7a7..9676004e01e 100644
--- a/regression-test/suites/mtmv_p0/test_build_mtmv.groovy
+++ b/regression-test/suites/mtmv_p0/test_build_mtmv.groovy
@@ -69,7 +69,6 @@ suite("test_build_mtmv") {
     sql """drop materialized view if exists ${mvName};"""
     sql """drop materialized view if exists ${mvNameRenamed};"""
 
-    // show create table
     sql """
         CREATE MATERIALIZED VIEW ${mvName}
         (aa comment "aaa",bb)
@@ -84,10 +83,6 @@ suite("test_build_mtmv") {
         SELECT id, username FROM ${tableName};
         """
 
-    def showCreateTableResult = sql """show create table ${mvName}"""
-    logger.info("showCreateTableResult: " + showCreateTableResult.toString())
-    assertTrue(showCreateTableResult.toString().contains("CREATE MATERIALIZED 
VIEW `multi_mv_test_create_mtmv` (\n  `aa` BIGINT NULL COMMENT 'aaa',\n  `bb` 
VARCHAR(20) NULL\n) ENGINE=MATERIALIZED_VIEW\nCOMMENT 'comment1'\nDISTRIBUTED 
BY RANDOM BUCKETS 2\nPROPERTIES"))
-
     // desc
     def descTableAllResult = sql """desc ${mvName} all"""
     logger.info("descTableAllResult: " + descTableAllResult.toString())


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

Reply via email to