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

morningman 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 3791de3cfa3 [feature](mtmv)(6)implement cancel method (#27541)
3791de3cfa3 is described below

commit 3791de3cfa3dabd253b6a4785372755a6e1d0d53
Author: zhangdong <[email protected]>
AuthorDate: Mon Nov 27 09:49:46 2023 +0800

    [feature](mtmv)(6)implement cancel method (#27541)
    
    1.implement cancel task method
    2.fix `show create table ` not display `comment`
---
 .../src/main/java/org/apache/doris/catalog/Env.java   | 15 +++++----------
 .../apache/doris/job/extensions/mtmv/MTMVTask.java    | 13 +++++++++----
 .../doris/nereids/parser/LogicalPlanBuilder.java      |  9 +++++++--
 regression-test/data/mtmv_p0/test_create_mtmv.out     |  6 ------
 regression-test/suites/mtmv_p0/test_build_mtmv.groovy | 19 +++++++++++++++++++
 5 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 6ddeb3977a0..5eb735353b0 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -2965,7 +2965,7 @@ public class Env {
                 || table.getType() == TableType.HIVE || table.getType() == 
TableType.JDBC) {
             sb.append("EXTERNAL ");
         }
-        sb.append("TABLE ");
+        sb.append(table.getType() != TableType.MATERIALIZED_VIEW ? "TABLE " : 
"MATERIALIZED VIEW ");
 
         if (!Strings.isNullOrEmpty(dbName)) {
             sb.append("`").append(dbName).append("`.");
@@ -2995,7 +2995,7 @@ public class Env {
                 sb.append("  ").append(column.toSql());
             }
         }
-        if (table.getType() == TableType.OLAP) {
+        if (table instanceof OlapTable) {
             OlapTable olapTable = (OlapTable) table;
             if (CollectionUtils.isNotEmpty(olapTable.getIndexes())) {
                 for (Index index : olapTable.getIndexes()) {
@@ -3007,7 +3007,7 @@ public class Env {
         sb.append("\n) ENGINE=");
         sb.append(table.getType().name());
 
-        if (table.getType() == TableType.OLAP || table.getType() == 
TableType.MATERIALIZED_VIEW) {
+        if (table instanceof OlapTable) {
             OlapTable olapTable = (OlapTable) table;
             // keys
             String keySql = olapTable.getKeysType().toSql();
@@ -3015,10 +3015,7 @@ public class Env {
                 // after #18621, use can create a DUP_KEYS olap table without 
key columns
                 // and get a ddl schema without key type and key columns
             } else {
-                sb.append("\n").append(table.getType() == TableType.OLAP
-                                ? keySql
-                                : keySql.substring("DUPLICATE ".length()))
-                        .append("(");
+                sb.append("\n").append(keySql).append("(");
                 List<String> keysColumnNames = Lists.newArrayList();
                 Map<Integer, String> clusterKeysColumnNamesToId = new 
TreeMap<>();
                 for (Column column : olapTable.getBaseSchema()) {
@@ -3047,9 +3044,7 @@ public class Env {
                 return;
             }
 
-            if (table.getType() != TableType.MATERIALIZED_VIEW) {
-                addTableComment(olapTable, sb);
-            }
+            addTableComment(olapTable, sb);
 
             // partition
             PartitionInfo partitionInfo = olapTable.getPartitionInfo();
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java 
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
index f4d92244289..7ddddc018fb 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
@@ -59,6 +59,7 @@ public class MTMVTask extends AbstractTask {
 
     private MTMV mtmv;
     private MTMVRelation relation;
+    private StmtExecutor executor;
 
     public MTMVTask(long dbId, long mtmvId) {
         this.dbId = dbId;
@@ -73,7 +74,7 @@ public class MTMVTask extends AbstractTask {
             // Every time a task is run, the relation is regenerated because 
baseTables and baseViews may change,
             // such as deleting a table and creating a view with the same name
             relation = MTMVCacheManager.generateMTMVRelation(mtmv, ctx);
-            StmtExecutor executor = new StmtExecutor(ctx, sql);
+            executor = new StmtExecutor(ctx, sql);
             executor.execute(queryId);
         } catch (Throwable e) {
             LOG.warn(e);
@@ -82,20 +83,23 @@ public class MTMVTask extends AbstractTask {
     }
 
     @Override
-    public void onFail() throws JobException {
+    public synchronized void onFail() throws JobException {
         super.onFail();
         after();
     }
 
     @Override
-    public void onSuccess() throws JobException {
+    public synchronized void onSuccess() throws JobException {
         super.onSuccess();
         after();
     }
 
     @Override
-    public void cancel() throws JobException {
+    public synchronized void cancel() throws JobException {
         super.cancel();
+        if (executor != null) {
+            executor.cancel();
+        }
         after();
     }
 
@@ -165,5 +169,6 @@ public class MTMVTask extends AbstractTask {
                 .addMTMVTaskResult(new 
TableNameInfo(mtmv.getQualifiedDbName(), mtmv.getName()), this, relation);
         mtmv = null;
         relation = null;
+        executor = null;
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 9fdb4635e7b..a1118525b8a 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -492,9 +492,12 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
                 bucketNum, ctx.HASH() != null ? 
visitIdentifierList(ctx.hashKeys) : null);
         Map<String, String> properties = ctx.propertyClause() != null
                 ? Maps.newHashMap(visitPropertyClause(ctx.propertyClause())) : 
Maps.newHashMap();
+        String comment = ctx.STRING_LITERAL() == null ? "" : 
LogicalPlanBuilderAssistant.escapeBackSlash(
+                ctx.STRING_LITERAL().getText().substring(1, 
ctx.STRING_LITERAL().getText().length() - 1));
+
         return new CreateMTMVCommand(new CreateMTMVInfo(ctx.EXISTS() != null, 
new TableNameInfo(nameParts),
                 ctx.keys != null ? visitIdentifierList(ctx.keys) : 
ImmutableList.of(),
-                ctx.STRING_LITERAL() != null ? ctx.STRING_LITERAL().getText() 
: null,
+                comment,
                 desc, properties, logicalPlan, querySql,
                 new MTMVRefreshInfo(buildMode, refreshMethod, 
refreshTriggerInfo),
                 ctx.cols == null ? Lists.newArrayList() : 
visitSimpleColumnDefs(ctx.cols)
@@ -513,8 +516,10 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
 
     @Override
     public SimpleColumnDefinition visitSimpleColumnDef(SimpleColumnDefContext 
ctx) {
+        String comment = ctx.STRING_LITERAL() == null ? "" : 
LogicalPlanBuilderAssistant.escapeBackSlash(
+                ctx.STRING_LITERAL().getText().substring(1, 
ctx.STRING_LITERAL().getText().length() - 1));
         return new SimpleColumnDefinition(ctx.colName.getText().toLowerCase(),
-                ctx.STRING_LITERAL() != null ? ctx.STRING_LITERAL().getText() 
: null);
+                comment);
     }
 
     /**
diff --git a/regression-test/data/mtmv_p0/test_create_mtmv.out 
b/regression-test/data/mtmv_p0/test_create_mtmv.out
deleted file mode 100644
index 75d55317997..00000000000
--- a/regression-test/data/mtmv_p0/test_create_mtmv.out
+++ /dev/null
@@ -1,6 +0,0 @@
--- This file is automatically generated. You should know what you did if you 
want to edit this
--- !select --
-clz    200
-lisi   300
-zhangsang      200
-
diff --git a/regression-test/suites/mtmv_p0/test_build_mtmv.groovy 
b/regression-test/suites/mtmv_p0/test_build_mtmv.groovy
index a08c49a8b98..ca03c38b7c5 100644
--- a/regression-test/suites/mtmv_p0/test_build_mtmv.groovy
+++ b/regression-test/suites/mtmv_p0/test_build_mtmv.groovy
@@ -57,6 +57,25 @@ 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)
+        BUILD DEFERRED REFRESH COMPLETE ON MANUAL
+        COMMENT "comment1"
+        DISTRIBUTED BY RANDOM BUCKETS 2
+        PROPERTIES ('replication_num' = '1')
+        AS
+        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 10\nPROPERTIES"))
+    sql """
+        DROP MATERIALIZED VIEW ${mvName}
+    """
+
     // IMMEDIATE MANUAL
     sql """
         CREATE MATERIALIZED VIEW ${mvName}


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

Reply via email to