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 510d88f31505e964a49b7701358fa0302fb78cf3
Author: zhangdong <[email protected]>
AuthorDate: Mon Jan 22 20:42:25 2024 +0800

    [fix](mtmv)return MTMV with at least one available partition #30156
---
 .../org/apache/doris/mtmv/MTMVRelationManager.java  | 21 ++++++++++++++++-----
 .../mv/InitMaterializationContextHook.java          |  2 +-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelationManager.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelationManager.java
index 35bf777acb5..77414e4fc88 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelationManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelationManager.java
@@ -33,6 +33,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.info.RefreshMTMVInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.ResumeMTMVInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
 import org.apache.doris.persist.AlterMTMV;
+import org.apache.doris.qe.ConnectContext;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
@@ -53,16 +54,26 @@ public class MTMVRelationManager implements MTMVHookService 
{
     private static final Logger LOG = 
LogManager.getLogger(MTMVRelationManager.class);
     private Map<BaseTableInfo, Set<BaseTableInfo>> tableMTMVs = 
Maps.newConcurrentMap();
 
-    public Set<BaseTableInfo> getMtmvsByBaseTable(BaseTableInfo table) {
+    private Set<BaseTableInfo> getMtmvsByBaseTable(BaseTableInfo table) {
         return tableMTMVs.getOrDefault(table, ImmutableSet.of());
     }
 
-    public Set<MTMV> getAvailableMTMVs(List<BaseTableInfo> tableInfos) {
+    /**
+     * if At least one partition is available, return this mtmv
+     *
+     * @param tableInfos
+     * @param ctx
+     * @return
+     */
+    public Set<MTMV> getAvailableMTMVs(List<BaseTableInfo> tableInfos, 
ConnectContext ctx) {
         Set<MTMV> res = Sets.newHashSet();
-        Set<BaseTableInfo> mvInfos = getAvailableMTMVInfos(tableInfos);
+        Set<BaseTableInfo> mvInfos = getMTMVInfos(tableInfos);
         for (BaseTableInfo tableInfo : mvInfos) {
             try {
-                res.add((MTMV) MTMVUtil.getTable(tableInfo));
+                MTMV mtmv = (MTMV) MTMVUtil.getTable(tableInfo);
+                if 
(!CollectionUtils.isEmpty(MTMVUtil.getMTMVCanRewritePartitions(mtmv, ctx))) {
+                    res.add(mtmv);
+                }
             } catch (AnalysisException e) {
                 // not throw exception to client, just ignore it
                 LOG.warn("getTable failed: {}", tableInfo.toString(), e);
@@ -71,7 +82,7 @@ public class MTMVRelationManager implements MTMVHookService {
         return res;
     }
 
-    public Set<BaseTableInfo> getAvailableMTMVInfos(List<BaseTableInfo> 
tableInfos) {
+    private Set<BaseTableInfo> getMTMVInfos(List<BaseTableInfo> tableInfos) {
         Set<BaseTableInfo> mvInfos = Sets.newHashSet();
         for (BaseTableInfo tableInfo : tableInfos) {
             mvInfos.addAll(getMtmvsByBaseTable(tableInfo));
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
index 07a4ff208bc..baf714fe280 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
@@ -70,7 +70,7 @@ public class InitMaterializationContextHook implements 
PlannerHook {
         List<BaseTableInfo> usedBaseTables =
                 
collectedTables.stream().map(BaseTableInfo::new).collect(Collectors.toList());
         Set<MTMV> availableMTMVs = 
Env.getCurrentEnv().getMtmvService().getRelationManager()
-                .getAvailableMTMVs(usedBaseTables);
+                .getAvailableMTMVs(usedBaseTables, 
cascadesContext.getConnectContext());
         if (availableMTMVs.isEmpty()) {
             return;
         }


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

Reply via email to