Skip to content

Commit

Permalink
[fix](mtmv)fix when related table drop partition,mv partition is sync… (
Browse files Browse the repository at this point in the history
#36602)

pick: #36547
  • Loading branch information
zddr authored Jul 2, 2024
1 parent 5bb6642 commit 03942f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ public static boolean isSyncWithPartitions(MTMV mtmv, String mtmvPartitionName,
if (!relatedTable.needAutoRefresh()) {
return true;
}
// check if partitions of related table if changed
Set<String> snapshotPartitions = mtmv.getRefreshSnapshot().getSnapshotPartitions(mtmvPartitionName);
if (!Objects.equals(relatedPartitionNames, snapshotPartitions)) {
return false;
}
for (String relatedPartitionName : relatedPartitionNames) {
MTMVSnapshotIf relatedPartitionCurrentSnapshot = relatedTable
.getPartitionSnapshot(relatedPartitionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.mtmv;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.collections.MapUtils;

Expand Down Expand Up @@ -46,6 +47,14 @@ public boolean equalsWithRelatedPartition(String mtmvPartitionName, String relat
return relatedPartitionSnapshot.equals(relatedPartitionCurrentSnapshot);
}

public Set<String> getSnapshotPartitions(String mtmvPartitionName) {
MTMVRefreshPartitionSnapshot partitionSnapshot = partitionSnapshots.get(mtmvPartitionName);
if (partitionSnapshot == null) {
return Sets.newHashSet();
}
return partitionSnapshot.getPartitions().keySet();
}

public boolean equalsWithBaseTable(String mtmvPartitionName, long baseTableId,
MTMVSnapshotIf baseTableCurrentSnapshot) {
MTMVRefreshPartitionSnapshot partitionSnapshot = partitionSnapshots.get(mtmvPartitionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public void setUp() throws NoSuchMethodException, SecurityException, AnalysisExc
refreshSnapshot.equalsWithRelatedPartition(anyString, anyString, (MTMVSnapshotIf) any);
minTimes = 0;
result = true;

refreshSnapshot.getSnapshotPartitions(anyString);
minTimes = 0;
result = Sets.newHashSet("name2");
}
};
}
Expand Down Expand Up @@ -160,6 +164,20 @@ public void testIsSyncWithPartition() throws AnalysisException {
Assert.assertTrue(isSyncWithPartition);
}

@Test
public void testIsSyncWithPartitionNotEqual() throws AnalysisException {
new Expectations() {
{
refreshSnapshot.getSnapshotPartitions(anyString);
minTimes = 0;
result = Sets.newHashSet("name2", "name3");
}
};
boolean isSyncWithPartition = MTMVPartitionUtil
.isSyncWithPartitions(mtmv, "name1", baseOlapTable, Sets.newHashSet("name2"));
Assert.assertFalse(isSyncWithPartition);
}

@Test
public void testIsSyncWithPartitionNotSync() throws AnalysisException {
new Expectations() {
Expand Down

0 comments on commit 03942f2

Please sign in to comment.