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 af35f40fae8 [enhance](mtmv) mtmv query sql expand star (#36543)
af35f40fae8 is described below

commit af35f40fae84db6aac099f9726607ccbb310694a
Author: zhangdong <493738...@qq.com>
AuthorDate: Tue Aug 13 19:34:12 2024 +0800

    [enhance](mtmv) mtmv query sql expand star (#36543)
    
    before: SELECT * from user
    
    now: SELECT `internal`.`zd`.`user`.`k1`, `internal`.`zd`.`user`.`k2`
    from `internal`.`zd`.`user`
    
    Therefore, there is no need for EnvInfo to store catalog and db
    information when creating materialized views
---
 .../org/apache/doris/analysis/CreateMTMVStmt.java  |  9 +--
 .../main/java/org/apache/doris/catalog/MTMV.java   | 15 ----
 .../org/apache/doris/catalog/OlapTableFactory.java | 13 +---
 .../apache/doris/job/extensions/mtmv/MTMVTask.java | 12 +---
 .../main/java/org/apache/doris/mtmv/EnvInfo.java   | 51 --------------
 .../java/org/apache/doris/mtmv/MTMVPlanUtil.java   | 35 ---------
 .../trees/plans/commands/info/AlterViewInfo.java   |  2 +-
 .../trees/plans/commands/info/BaseViewInfo.java    | 17 ++++-
 .../trees/plans/commands/info/CreateMTMVInfo.java  | 34 +++++++--
 .../trees/plans/commands/info/CreateViewInfo.java  |  2 +-
 .../doris/tablefunction/MetadataGenerator.java     |  1 -
 .../tablefunction/MvInfosTableValuedFunction.java  |  1 -
 .../test/java/org/apache/doris/mtmv/MTMVTest.java  |  2 -
 .../data/mtmv_p0/test_expand_star_mtmv.out         |  7 ++
 .../suites/mtmv_p0/test_env_db_dropped_mtmv.groovy |  2 +-
 .../suites/mtmv_p0/test_expand_star_mtmv.groovy    | 82 ++++++++++++++++++++++
 .../suites/mtmv_p0/test_show_create_mtmv.groovy    |  2 +-
 17 files changed, 139 insertions(+), 148 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMTMVStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMTMVStmt.java
index 9421bb047c4..d586535572b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMTMVStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMTMVStmt.java
@@ -19,7 +19,6 @@ package org.apache.doris.analysis;
 
 import org.apache.doris.catalog.Column;
 import org.apache.doris.catalog.Index;
-import org.apache.doris.mtmv.EnvInfo;
 import org.apache.doris.mtmv.MTMVPartitionInfo;
 import org.apache.doris.mtmv.MTMVRefreshInfo;
 import org.apache.doris.mtmv.MTMVRelation;
@@ -31,7 +30,6 @@ import java.util.Map;
 public class CreateMTMVStmt extends CreateTableStmt {
     private final MTMVRefreshInfo refreshInfo;
     private final String querySql;
-    private final EnvInfo envInfo;
     private Map<String, String> mvProperties;
     private MTMVPartitionInfo mvPartitionInfo;
     private MTMVRelation relation;
@@ -39,12 +37,11 @@ public class CreateMTMVStmt extends CreateTableStmt {
     public CreateMTMVStmt(boolean ifNotExists, TableName mvName, List<Column> 
columns,
             MTMVRefreshInfo refreshInfo, KeysDesc keyDesc, DistributionDesc 
distributionDesc,
             Map<String, String> properties, Map<String, String> mvProperties, 
String querySql, String comment,
-            EnvInfo envInfo, PartitionDesc partitionDesc, MTMVPartitionInfo 
mvPartitionInfo, MTMVRelation relation) {
+            PartitionDesc partitionDesc, MTMVPartitionInfo mvPartitionInfo, 
MTMVRelation relation) {
         super(ifNotExists, false, mvName, columns, new ArrayList<Index>(), 
DEFAULT_ENGINE_NAME, keyDesc, partitionDesc,
                 distributionDesc, properties, null, comment, null, null);
         this.refreshInfo = refreshInfo;
         this.querySql = querySql;
-        this.envInfo = envInfo;
         this.mvProperties = mvProperties;
         this.mvPartitionInfo = mvPartitionInfo;
         this.relation = relation;
@@ -58,10 +55,6 @@ public class CreateMTMVStmt extends CreateTableStmt {
         return querySql;
     }
 
-    public EnvInfo getEnvInfo() {
-        return envInfo;
-    }
-
     public Map<String, String> getMvProperties() {
         return mvProperties;
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
index 5097f83e249..cd7583193e8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
@@ -27,7 +27,6 @@ import org.apache.doris.common.io.Text;
 import org.apache.doris.common.util.PropertyAnalyzer;
 import org.apache.doris.job.common.TaskStatus;
 import org.apache.doris.job.extensions.mtmv.MTMVTask;
-import org.apache.doris.mtmv.EnvInfo;
 import org.apache.doris.mtmv.MTMVCache;
 import org.apache.doris.mtmv.MTMVJobInfo;
 import org.apache.doris.mtmv.MTMVJobManager;
@@ -75,8 +74,6 @@ public class MTMV extends OlapTable {
     private String querySql;
     @SerializedName("s")
     private MTMVStatus status;
-    @SerializedName("ei")
-    private EnvInfo envInfo;
     @SerializedName("ji")
     private MTMVJobInfo jobInfo;
     @SerializedName("mp")
@@ -108,7 +105,6 @@ public class MTMV extends OlapTable {
         this.type = TableType.MATERIALIZED_VIEW;
         this.querySql = params.querySql;
         this.refreshInfo = params.refreshInfo;
-        this.envInfo = params.envInfo;
         this.status = new MTMVStatus();
         this.jobInfo = new MTMVJobInfo(MTMVJobManager.MTMV_JOB_PREFIX + 
params.tableId);
         this.mvProperties = params.mvProperties;
@@ -140,10 +136,6 @@ public class MTMV extends OlapTable {
         }
     }
 
-    public EnvInfo getEnvInfo() {
-        return envInfo;
-    }
-
     public MTMVJobInfo getJobInfo() {
         readMvLock();
         try {
@@ -407,11 +399,6 @@ public class MTMV extends OlapTable {
         this.status = status;
     }
 
-    // for test
-    public void setEnvInfo(EnvInfo envInfo) {
-        this.envInfo = envInfo;
-    }
-
     // for test
     public void setJobInfo(MTMVJobInfo jobInfo) {
         this.jobInfo = jobInfo;
@@ -467,7 +454,6 @@ public class MTMV extends OlapTable {
         refreshInfo = materializedView.refreshInfo;
         querySql = materializedView.querySql;
         status = materializedView.status;
-        envInfo = materializedView.envInfo;
         jobInfo = materializedView.jobInfo;
         mvProperties = materializedView.mvProperties;
         relation = materializedView.relation;
@@ -485,7 +471,6 @@ public class MTMV extends OlapTable {
         sb.append("refreshInfo=").append(refreshInfo);
         sb.append(", querySql='").append(querySql).append('\'');
         sb.append(", status=").append(status);
-        sb.append(", envInfo=").append(envInfo);
         if (jobInfo != null) {
             sb.append(", jobInfo=").append(jobInfo.toInfoString());
         }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTableFactory.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTableFactory.java
index 7d11ed7bdd9..cc86535c8b1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTableFactory.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTableFactory.java
@@ -21,7 +21,6 @@ import org.apache.doris.analysis.CreateMTMVStmt;
 import org.apache.doris.analysis.CreateTableStmt;
 import org.apache.doris.analysis.DdlStmt;
 import org.apache.doris.catalog.TableIf.TableType;
-import org.apache.doris.mtmv.EnvInfo;
 import org.apache.doris.mtmv.MTMVPartitionInfo;
 import org.apache.doris.mtmv.MTMVRefreshInfo;
 import org.apache.doris.mtmv.MTMVRelation;
@@ -48,7 +47,6 @@ public class OlapTableFactory {
 
     public static class MTMVParams extends BuildParams {
         public MTMVRefreshInfo refreshInfo;
-        public EnvInfo envInfo;
         public String querySql;
         public Map<String, String> mvProperties;
         public MTMVPartitionInfo mvPartitionInfo;
@@ -154,14 +152,6 @@ public class OlapTableFactory {
         return this;
     }
 
-    private OlapTableFactory withEnvInfo(EnvInfo envInfo) {
-        Preconditions.checkState(params instanceof MTMVParams, "Invalid 
argument for "
-                + params.getClass().getSimpleName());
-        MTMVParams mtmvParams = (MTMVParams) params;
-        mtmvParams.envInfo = envInfo;
-        return this;
-    }
-
     private OlapTableFactory withMvPartitionInfo(MTMVPartitionInfo 
mvPartitionInfo) {
         Preconditions.checkState(params instanceof MTMVParams, "Invalid 
argument for "
                 + params.getClass().getSimpleName());
@@ -189,8 +179,7 @@ public class OlapTableFactory {
                     .withQuerySql(createMTMVStmt.getQuerySql())
                     .withMvProperties(createMTMVStmt.getMvProperties())
                     .withMvPartitionInfo(createMTMVStmt.getMvPartitionInfo())
-                    .withMvRelation(createMTMVStmt.getRelation())
-                    .withEnvInfo(createMTMVStmt.getEnvInfo());
+                    .withMvRelation(createMTMVStmt.getRelation());
         }
     }
 }
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 0207301c2d2..5c48649bf36 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
@@ -25,7 +25,6 @@ import org.apache.doris.catalog.TableIf;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.DdlException;
 import org.apache.doris.common.FeConstants;
-import org.apache.doris.common.Pair;
 import org.apache.doris.common.UserException;
 import org.apache.doris.common.util.DebugUtil;
 import org.apache.doris.common.util.TimeUtils;
@@ -204,15 +203,8 @@ public class MTMVTask extends AbstractTask {
             }
         } catch (Throwable e) {
             if (getStatus() == TaskStatus.RUNNING) {
-                StringBuilder errMsg = new StringBuilder();
-                // when env ctl/db not exist, need give client tips
-                Pair<Boolean, String> pair = 
MTMVPlanUtil.checkEnvInfo(mtmv.getEnvInfo(), ctx);
-                if (!pair.first) {
-                    errMsg.append(pair.second);
-                }
-                errMsg.append(e.getMessage());
-                LOG.warn("run task failed: ", errMsg.toString());
-                throw new JobException(errMsg.toString(), e);
+                LOG.warn("run task failed: ", e.getMessage());
+                throw new JobException(e.getMessage(), e);
             } else {
                 // if status is not `RUNNING`,maybe the task was canceled, 
therefore, it is a normal situation
                 LOG.info("task [{}] interruption running, because status is 
[{}]", getTaskId(), getStatus());
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java
deleted file mode 100644
index 97ad491cb31..00000000000
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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.
-
-package org.apache.doris.mtmv;
-
-import com.google.gson.annotations.SerializedName;
-
-/**
- * EnvInfo
- */
-public class EnvInfo {
-    @SerializedName("ci")
-    private long ctlId;
-    @SerializedName("di")
-    private long dbId;
-
-    public EnvInfo(long ctlId, long dbId) {
-        this.ctlId = ctlId;
-        this.dbId = dbId;
-    }
-
-    public long getCtlId() {
-        return ctlId;
-    }
-
-    public long getDbId() {
-        return dbId;
-    }
-
-    @Override
-    public String toString() {
-        return "EnvInfo{"
-                + "ctlId='" + ctlId + '\''
-                + ", dbId='" + dbId + '\''
-                + '}';
-    }
-}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
index cf80e58eb7e..27fe6b8ff6b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
@@ -19,13 +19,10 @@ package org.apache.doris.mtmv;
 
 import org.apache.doris.analysis.StatementBase;
 import org.apache.doris.analysis.UserIdentity;
-import org.apache.doris.catalog.DatabaseIf;
 import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.MTMV;
 import org.apache.doris.catalog.TableIf;
 import org.apache.doris.catalog.TableIf.TableType;
-import org.apache.doris.common.Pair;
-import org.apache.doris.datasource.CatalogIf;
 import org.apache.doris.mysql.privilege.Auth;
 import org.apache.doris.nereids.NereidsPlanner;
 import org.apache.doris.nereids.exceptions.ParseException;
@@ -63,41 +60,9 @@ public class MTMVPlanUtil {
         if (workloadGroup.isPresent()) {
             ctx.getSessionVariable().setWorkloadGroup(workloadGroup.get());
         }
-        // switch catalog;
-        CatalogIf catalog = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(mtmv.getEnvInfo().getCtlId());
-        // if catalog not exist, it may not have any impact, so there is no 
error and it will be returned directly
-        if (catalog == null) {
-            return ctx;
-        }
-        ctx.changeDefaultCatalog(catalog.getName());
-        // use db
-        Optional<? extends DatabaseIf<? extends TableIf>> databaseIf = 
catalog.getDb(mtmv.getEnvInfo().getDbId());
-        // if db not exist, it may not have any impact, so there is no error 
and it will be returned directly
-        if (!databaseIf.isPresent()) {
-            return ctx;
-        }
-        ctx.setDatabase(databaseIf.get().getFullName());
         return ctx;
     }
 
-    public static Pair<Boolean, String> checkEnvInfo(EnvInfo envInfo, 
ConnectContext ctx) {
-        if (envInfo.getCtlId() != ctx.getCurrentCatalog().getId()) {
-            return Pair.of(false, String.format(
-                    "The catalog selected when creating the materialized view 
was %s, "
-                            + "but now this catalog has been deleted. "
-                            + "Please recreate the materialized view.",
-                    envInfo.getCtlId()));
-        }
-        if (envInfo.getDbId() != ctx.getCurrentDbId()) {
-            return Pair.of(false, String.format(
-                    "The database selected when creating the materialized view 
was %s, "
-                            + "but now this database has been deleted. "
-                            + "Please recreate the materialized view.",
-                    envInfo.getDbId()));
-        }
-        return Pair.of(true, "");
-    }
-
     public static MTMVRelation generateMTMVRelation(MTMV mtmv, ConnectContext 
ctx) {
         // Should not make table without data to empty relation when analyze 
the related table,
         // so add disable rules
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java
index 73231ab461c..c4b20acaf01 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java
@@ -104,7 +104,7 @@ public class AlterViewInfo extends BaseViewInfo {
         AlterViewStmt alterViewStmt = new 
AlterViewStmt(viewName.transferToTableName(), cols,
                 null);
         // expand star(*) in project list and replace table name with qualifier
-        String rewrittenSql = 
rewriteSql(ctx.getStatementContext().getIndexInSqlToString());
+        String rewrittenSql = 
rewriteSql(ctx.getStatementContext().getIndexInSqlToString(), querySql);
 
         // rewrite project alias
         rewrittenSql = rewriteProjectsToUserDefineAlias(rewrittenSql);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
index 79a4521309a..591c14a71ce 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
@@ -107,7 +107,15 @@ public class BaseViewInfo {
         analyzedPlan.accept(PlanSlotFinder.INSTANCE, 
ctx.getStatementContext());
     }
 
-    protected String rewriteSql(TreeMap<Pair<Integer, Integer>, String> 
indexStringSqlMap) {
+    /**
+     * Add the full path to the field
+     *
+     * @param indexStringSqlMap key is the start and end position of the sql 
substring that needs to be replaced,
+     *         and value is the new string used for replacement.
+     * @param querySql origin query sql
+     * @return sql rewritten sql
+     */
+    public static String rewriteSql(TreeMap<Pair<Integer, Integer>, String> 
indexStringSqlMap, String querySql) {
         StringBuilder builder = new StringBuilder();
         int beg = 0;
         for (Map.Entry<Pair<Integer, Integer>, String> entry : 
indexStringSqlMap.entrySet()) {
@@ -245,8 +253,11 @@ public class BaseViewInfo {
         }
     }
 
-    private static class PlanSlotFinder extends DefaultPlanVisitor<Void, 
StatementContext> {
-        private static PlanSlotFinder INSTANCE = new PlanSlotFinder();
+    /**
+     * PlanSlotFinder
+     */
+    public static class PlanSlotFinder extends DefaultPlanVisitor<Void, 
StatementContext> {
+        public static PlanSlotFinder INSTANCE = new PlanSlotFinder();
 
         @Override
         public Void visitLogicalView(LogicalView<? extends Plan> alias, 
StatementContext context) {
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 2e8774f4f8a..91940efecb1 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
@@ -37,7 +37,6 @@ 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;
-import org.apache.doris.mtmv.EnvInfo;
 import org.apache.doris.mtmv.MTMVPartitionInfo;
 import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType;
 import org.apache.doris.mtmv.MTMVPartitionUtil;
@@ -48,10 +47,12 @@ import org.apache.doris.mtmv.MTMVRelatedTableIf;
 import org.apache.doris.mtmv.MTMVRelation;
 import org.apache.doris.mtmv.MTMVUtil;
 import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.CascadesContext;
 import org.apache.doris.nereids.NereidsPlanner;
 import org.apache.doris.nereids.StatementContext;
 import org.apache.doris.nereids.analyzer.UnboundResultSink;
 import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.parser.NereidsParser;
 import org.apache.doris.nereids.properties.PhysicalProperties;
 import org.apache.doris.nereids.rules.exploration.mv.MaterializedViewUtils;
 import org.apache.doris.nereids.trees.expressions.Expression;
@@ -59,6 +60,8 @@ import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.algebra.OneRowRelation;
 import 
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import 
org.apache.doris.nereids.trees.plans.commands.info.BaseViewInfo.AnalyzerForCreateView;
+import 
org.apache.doris.nereids.trees.plans.commands.info.BaseViewInfo.PlanSlotFinder;
 import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
@@ -101,11 +104,10 @@ public class CreateMTMVInfo {
     private Map<String, String> mvProperties = Maps.newHashMap();
 
     private final LogicalPlan logicalQuery;
-    private final String querySql;
+    private String querySql;
     private final MTMVRefreshInfo refreshInfo;
     private final List<ColumnDefinition> columns = Lists.newArrayList();
     private final List<SimpleColumnDefinition> simpleColumnDefinitions;
-    private final EnvInfo envInfo;
     private final MTMVPartitionDefinition mvPartitionDefinition;
     private PartitionDesc partitionDesc;
     private MTMVRelation relation;
@@ -132,8 +134,6 @@ public class CreateMTMVInfo {
         this.refreshInfo = Objects.requireNonNull(refreshInfo, "require 
refreshInfo object");
         this.simpleColumnDefinitions = Objects
                 .requireNonNull(simpleColumnDefinitions, "require 
simpleColumnDefinitions object");
-        this.envInfo = new 
EnvInfo(ConnectContext.get().getCurrentCatalog().getId(),
-                ConnectContext.get().getCurrentDbId());
         this.mvPartitionDefinition = Objects
                 .requireNonNull(mvPartitionDefinition, "require 
mtmvPartitionInfo object");
     }
@@ -182,6 +182,28 @@ public class CreateMTMVInfo {
         refreshInfo.validate();
 
         analyzeProperties();
+        rewriteQuerySql(ctx);
+    }
+
+    private void rewriteQuerySql(ConnectContext ctx) {
+        analyzeAndFillRewriteSqlMap(querySql, ctx);
+        querySql = 
BaseViewInfo.rewriteSql(ctx.getStatementContext().getIndexInSqlToString(), 
querySql);
+    }
+
+    private void analyzeAndFillRewriteSqlMap(String sql, ConnectContext ctx) {
+        StatementContext stmtCtx = ctx.getStatementContext();
+        LogicalPlan parsedViewPlan = new 
NereidsParser().parseForCreateView(sql);
+        if (parsedViewPlan instanceof UnboundResultSink) {
+            parsedViewPlan = (LogicalPlan) ((UnboundResultSink<?>) 
parsedViewPlan).child();
+        }
+        CascadesContext viewContextForStar = CascadesContext.initContext(
+                stmtCtx, parsedViewPlan, PhysicalProperties.ANY);
+        AnalyzerForCreateView analyzerForStar = new 
AnalyzerForCreateView(viewContextForStar);
+        analyzerForStar.analyze();
+        Plan analyzedPlan = viewContextForStar.getRewritePlan();
+        // Traverse all slots in the plan, and add the slot's location 
information
+        // and the fully qualified replacement string to the 
indexInSqlToString of the StatementContext.
+        analyzedPlan.accept(PlanSlotFinder.INSTANCE, 
ctx.getStatementContext());
     }
 
     private void analyzeProperties() {
@@ -414,7 +436,7 @@ public class CreateMTMVInfo {
                 .map(ColumnDefinition::translateToCatalogStyle)
                 .collect(Collectors.toList());
         return new CreateMTMVStmt(ifNotExists, tableName, catalogColumns, 
refreshInfo, keysDesc,
-                distribution.translateToCatalogStyle(), properties, 
mvProperties, querySql, comment, envInfo,
+                distribution.translateToCatalogStyle(), properties, 
mvProperties, querySql, comment,
                 partitionDesc, mvPartitionInfo, relation);
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateViewInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateViewInfo.java
index 65eb3453ec3..a881be046e7 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateViewInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateViewInfo.java
@@ -97,7 +97,7 @@ public class CreateViewInfo extends BaseViewInfo {
         CreateViewStmt createViewStmt = new CreateViewStmt(ifNotExists, 
viewName.transferToTableName(), cols, comment,
                 null);
         // expand star(*) in project list and replace table name with qualifier
-        String rewrittenSql = 
rewriteSql(ctx.getStatementContext().getIndexInSqlToString());
+        String rewrittenSql = 
rewriteSql(ctx.getStatementContext().getIndexInSqlToString(), querySql);
 
         // rewrite project alias
         rewrittenSql = rewriteProjectsToUserDefineAlias(rewrittenSql);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java
index b446cd4210a..c318aea0b1c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java
@@ -798,7 +798,6 @@ public class MetadataGenerator {
                 trow.addToColumnValue(new 
TCell().setStringVal(mv.getStatus().getRefreshState().name()));
                 trow.addToColumnValue(new 
TCell().setStringVal(mv.getRefreshInfo().toString()));
                 trow.addToColumnValue(new 
TCell().setStringVal(mv.getQuerySql()));
-                trow.addToColumnValue(new 
TCell().setStringVal(mv.getEnvInfo().toString()));
                 trow.addToColumnValue(new 
TCell().setStringVal(mv.getMvProperties().toString()));
                 trow.addToColumnValue(new 
TCell().setStringVal(mv.getMvPartitionInfo().toNameString()));
                 trow.addToColumnValue(new 
TCell().setBoolVal(MTMVPartitionUtil.isMTMVSync(mv)));
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MvInfosTableValuedFunction.java
 
b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MvInfosTableValuedFunction.java
index 4135173c34a..02002033bbe 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MvInfosTableValuedFunction.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MvInfosTableValuedFunction.java
@@ -57,7 +57,6 @@ public class MvInfosTableValuedFunction extends 
MetadataTableValuedFunction {
             new Column("RefreshState", ScalarType.createStringType()),
             new Column("RefreshInfo", ScalarType.createStringType()),
             new Column("QuerySql", ScalarType.createStringType()),
-            new Column("EnvInfo", ScalarType.createStringType()),
             new Column("MvProperties", ScalarType.createStringType()),
             new Column("MvPartitionInfo", ScalarType.createStringType()),
             new Column("SyncWithBaseTables", 
ScalarType.createType(PrimitiveType.BOOLEAN)));
diff --git a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVTest.java
index 64f0958beb8..ca226218cfc 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVTest.java
@@ -52,7 +52,6 @@ public class MTMVTest {
                 = "MTMV{refreshInfo=BUILD IMMEDIATE REFRESH COMPLETE ON 
SCHEDULE EVERY 2 SECOND STARTS ss, "
                 + "querySql='select * from xxx;', "
                 + "status=MTMVStatus{state=INIT, schemaChangeDetail='null', 
refreshState=INIT}, "
-                + "envInfo=EnvInfo{ctlId='1', dbId='2'}, "
                 + "jobInfo=MTMVJobInfo{jobName='job1', "
                 + "historyTasks=[MTMVTask{dbId=0, mtmvId=0, taskContext=null, "
                 + "needRefreshPartitions=null, completedPartitions=null, 
refreshMode=null} "
@@ -70,7 +69,6 @@ public class MTMVTest {
         mtmv.setRefreshInfo(buildMTMVRefreshInfo(mtmv));
         mtmv.setQuerySql("select * from xxx;");
         mtmv.setStatus(new MTMVStatus());
-        mtmv.setEnvInfo(new EnvInfo(1L, 2L));
         mtmv.setJobInfo(buildMTMVJobInfo(mtmv));
         mtmv.setMvProperties(new HashMap<>());
         mtmv.setRelation(new MTMVRelation(Sets.newHashSet(), 
Sets.newHashSet(), Sets.newHashSet()));
diff --git a/regression-test/data/mtmv_p0/test_expand_star_mtmv.out 
b/regression-test/data/mtmv_p0/test_expand_star_mtmv.out
new file mode 100644
index 00000000000..dbe6642fb42
--- /dev/null
+++ b/regression-test/data/mtmv_p0/test_expand_star_mtmv.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !query --
+SELECT 
`internal`.`regression_test_mtmv_p0`.`test_expand_star_mtmv_table`.`k2`, 
`internal`.`regression_test_mtmv_p0`.`test_expand_star_mtmv_table`.`k3` from 
`internal`.`regression_test_mtmv_p0`.`test_expand_star_mtmv_table`
+
+-- !udf --
+SELECT `regression_test_mtmv_p0`.`test_expand_star_mtmv_function` 
('2011-01-01','2011-01-03') as `k1` from 
`internal`.`regression_test_mtmv_p0`.`test_expand_star_mtmv_table`
+
diff --git a/regression-test/suites/mtmv_p0/test_env_db_dropped_mtmv.groovy 
b/regression-test/suites/mtmv_p0/test_env_db_dropped_mtmv.groovy
index 11063ba0e5b..516f5a648c7 100644
--- a/regression-test/suites/mtmv_p0/test_env_db_dropped_mtmv.groovy
+++ b/regression-test/suites/mtmv_p0/test_env_db_dropped_mtmv.groovy
@@ -89,5 +89,5 @@ suite("test_env_db_dropped_mtmv") {
     waitingMTMVTaskFinishedNotNeedSuccess(jobName)
     def msg = sql """select ErrorMsg from tasks('type'='mv') where JobName = 
'${jobName}' order by CreateTime DESC limit 1"""
     logger.info(msg.toString())
-    assertTrue(msg.toString().contains("has been deleted"))
+    assertTrue(msg.toString().contains("does not exist"))
 }
diff --git a/regression-test/suites/mtmv_p0/test_expand_star_mtmv.groovy 
b/regression-test/suites/mtmv_p0/test_expand_star_mtmv.groovy
new file mode 100644
index 00000000000..f550dc78c3d
--- /dev/null
+++ b/regression-test/suites/mtmv_p0/test_expand_star_mtmv.groovy
@@ -0,0 +1,82 @@
+// 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.
+
+import org.junit.Assert;
+
+suite("test_expand_star_mtmv","mtmv") {
+    String suiteName = "test_expand_star_mtmv"
+    String tableName = "${suiteName}_table"
+    String mvName = "${suiteName}_mv"
+    String functionName = "${suiteName}_function"
+    String dbName = context.config.getDbNameByFile(context.file)
+
+    sql """drop table if exists `${tableName}`"""
+    sql """drop materialized view if exists ${mvName};"""
+
+    sql """
+        CREATE TABLE ${tableName}
+        (
+            k2 INT,
+            k3 varchar(32)
+        )
+        DISTRIBUTED BY HASH(k2) BUCKETS 2
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+        """
+    sql """
+        CREATE MATERIALIZED VIEW ${mvName}
+        BUILD DEFERRED REFRESH AUTO ON MANUAL
+        DISTRIBUTED BY RANDOM BUCKETS 2
+        PROPERTIES (
+        'replication_num' = '1',
+        'version_info'='3'
+        )
+        AS
+        SELECT * from ${tableName};
+        """
+
+    order_qt_query "SELECT QuerySql FROM mv_infos('database'='${dbName}') 
where Name = '${mvName}'"
+
+    sql """drop materialized view if exists ${mvName};"""
+
+    def jarPath = 
"""${context.config.suitePath}/javaudf_p0/jars/java-udf-case-jar-with-dependencies.jar"""
+    scp_udf_file_to_all_be(jarPath)
+    log.info("jarPath:${jarPath}")
+
+    sql "drop function if exists ${functionName}(date, date)"
+    sql """ CREATE FUNCTION ${functionName}(date, date) RETURNS boolean 
PROPERTIES (
+            "file"="file://${jarPath}",
+            "symbol"="org.apache.doris.udf.DateTest1",
+            "type"="JAVA_UDF"
+        ); """
+
+    sql """
+        CREATE MATERIALIZED VIEW ${mvName}
+        BUILD DEFERRED REFRESH AUTO ON MANUAL
+        DISTRIBUTED BY RANDOM BUCKETS 2
+        PROPERTIES (
+        'replication_num' = '1',
+        'version_info'='3'
+        )
+        AS
+        SELECT ${functionName} ('2011-01-01','2011-01-03') as k1 from 
${tableName};
+        """
+    order_qt_udf "SELECT QuerySql FROM mv_infos('database'='${dbName}') where 
Name = '${mvName}'"
+    sql "drop function if exists ${functionName}(date, date)"
+    sql """drop materialized view if exists ${mvName};"""
+}
diff --git a/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy 
b/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
index 34cda2f6ffd..88f9de70865 100644
--- a/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
+++ b/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
@@ -60,7 +60,7 @@ suite("test_show_create_mtmv","mtmv") {
     assertTrue(showCreateMTMVResult.toString().contains("DUPLICATE KEY(`k1`, 
`k2`)"))
     assertTrue(showCreateMTMVResult.toString().contains("PARTITION BY 
(date_trunc(`k2`, 'month'))"))
     assertTrue(showCreateMTMVResult.toString().contains("DISTRIBUTED BY RANDOM 
BUCKETS 2"))
-    assertTrue(showCreateMTMVResult.toString().contains("SELECT * FROM"))
+    assertTrue(showCreateMTMVResult.toString().contains("SELECT"))
     assertTrue(showCreateMTMVResult.toString().contains("grace_period"))
 
     sql """drop materialized view if exists ${mvName};"""


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

Reply via email to