Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](mtmv)fix when related table drop partition,mv partition is sync… #36602

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading