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 2d6852bb2cf [fix](mtmv)fix when related table drop partition,mv
partition is sync (#36547)
2d6852bb2cf is described below
commit 2d6852bb2cf73eca01adcfa9028765b6ca402939
Author: zhangdong <[email protected]>
AuthorDate: Thu Jun 20 14:51:06 2024 +0800
[fix](mtmv)fix when related table drop partition,mv partition is sync
(#36547)
for example:
if mv's partition [mv_p1] is related with t1's partition [p1,p2]
when p2 dropped,
mv_p1'isSync should be false
---
.../java/org/apache/doris/mtmv/MTMVPartitionUtil.java | 5 +++++
.../org/apache/doris/mtmv/MTMVRefreshSnapshot.java | 9 +++++++++
.../org/apache/doris/mtmv/MTMVPartitionUtilTest.java | 18 ++++++++++++++++++
3 files changed, 32 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
index 82a649be37c..6595afb70f7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
@@ -325,6 +325,11 @@ public class MTMVPartitionUtil {
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);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java
index c1d07b27049..d48911275e8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java
@@ -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;
@@ -46,6 +47,14 @@ public class MTMVRefreshSnapshot {
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);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
index 261b750c796..c125e548d06 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
@@ -130,6 +130,10 @@ public class MTMVPartitionUtilTest {
refreshSnapshot.equalsWithRelatedPartition(anyString,
anyString, (MTMVSnapshotIf) any);
minTimes = 0;
result = true;
+
+ refreshSnapshot.getSnapshotPartitions(anyString);
+ minTimes = 0;
+ result = Sets.newHashSet("name2");
}
};
}
@@ -160,6 +164,20 @@ public class MTMVPartitionUtilTest {
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() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]