morrySnow commented on code in PR #39355:
URL: https://github.com/apache/doris/pull/39355#discussion_r1718434503


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVUtil.java:
##########
@@ -52,11 +54,17 @@ public class MTMVUtil {
      * @throws AnalysisException
      */
     public static TableIf getTable(BaseTableInfo baseTableInfo) throws 
AnalysisException {
-        TableIf table = Env.getCurrentEnv().getCatalogMgr()
-                .getCatalogOrAnalysisException(baseTableInfo.getCtlId())
-                .getDbOrAnalysisException(baseTableInfo.getDbId())
-                .getTableOrAnalysisException(baseTableInfo.getTableId());
-        return table;
+        // for compatible old version, not have name
+        if (StringUtils.isEmpty(baseTableInfo.getCtlName())) {
+            return Env.getCurrentEnv().getCatalogMgr()
+                    .getCatalogOrAnalysisException(baseTableInfo.getCtlId())
+                    .getDbOrAnalysisException(baseTableInfo.getDbId())
+                    .getTableOrAnalysisException(baseTableInfo.getTableId());
+        }
+        return Env.getCurrentEnv().getCatalogMgr()

Review Comment:
   it is better use else explicity to avoid incorrect modifications in future



##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshPartitionSnapshot.java:
##########
@@ -17,35 +17,88 @@
 
 package org.apache.doris.mtmv;
 
+import org.apache.doris.catalog.MTMV;
+
 import com.google.common.collect.Maps;
 import com.google.gson.annotations.SerializedName;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
 
 public class MTMVRefreshPartitionSnapshot {
+    private static final Logger LOG = LogManager.getLogger(MTMV.class);
     @SerializedName("p")
     private Map<String, MTMVSnapshotIf> partitions;
+    // old version only persist table id, we need `BaseTableInfo`, `tables` 
only for compatible old version
     @SerializedName("t")
+    @Deprecated
     private Map<Long, MTMVSnapshotIf> tables;
+    @SerializedName("ti")
+    private Map<BaseTableInfo, MTMVSnapshotIf> tablesInfo;
 
     public MTMVRefreshPartitionSnapshot() {
         this.partitions = Maps.newConcurrentMap();
         this.tables = Maps.newConcurrentMap();
+        this.tablesInfo = Maps.newConcurrentMap();
     }
 
     public Map<String, MTMVSnapshotIf> getPartitions() {
         return partitions;
     }
 
-    public Map<Long, MTMVSnapshotIf> getTables() {
-        return tables;
+    public MTMVSnapshotIf getTableSnapshot(BaseTableInfo table) {
+        if (tablesInfo.containsKey(table)) {
+            return tablesInfo.get(table);
+        }
+        // for compatible old version
+        return tables.get(table.getTableId());
+    }
+
+    public void addTableSnapshot(BaseTableInfo baseTableInfo, MTMVSnapshotIf 
tableSnapshot) {
+        tablesInfo.put(baseTableInfo, tableSnapshot);
+        // for compatible old version
+        tables.put(baseTableInfo.getTableId(), tableSnapshot);
     }
 
     @Override
     public String toString() {
         return "MTMVRefreshPartitionSnapshot{"
                 + "partitions=" + partitions
-                + ", tables=" + tables
+                + ", tablesInfo=" + tablesInfo
                 + '}';
     }
+
+    public void compatible(MTMV mtmv) {
+        if (tables.size() == tablesInfo.size()) {
+            return;
+        }
+        MTMVRelation relation = mtmv.getRelation();
+        if (relation == null || 
CollectionUtils.isEmpty(relation.getBaseTablesOneLevel())) {
+            return;
+        }
+        for (Entry<Long, MTMVSnapshotIf> entry : tables.entrySet()) {
+            Optional<BaseTableInfo> tableInfo = getByTableId(entry.getKey(),
+                    relation.getBaseTablesOneLevel());
+            if (tableInfo.isPresent()) {
+                tablesInfo.put(tableInfo.get(), entry.getValue());
+            } else {
+                LOG.info("MTMV compatible failed, tableId: {}, relationTables: 
{}", entry.getKey(),

Review Comment:
   warning?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to