From 85d7f56e906a3b76400ca6d2b127cb83d95bcbcd Mon Sep 17 00:00:00 2001 From: yujun Date: Thu, 11 Jun 2026 15:59:30 +0800 Subject: [PATCH 1/4] [fix](mtmv) Add null-safety to getBaseViewsOneLevel for backward compatibility getBaseViewsOneLevel() could return null when an MTMV was created before the baseViewsOneLevel field was introduced, causing NPE when querying information_schema.view_dependency via Stream.concat(). Key changes: - getBaseViewsOneLevel() now falls back to baseViews when baseViewsOneLevel is null, consistent with getBaseTablesOneLevel() Unit Test: - MTMVRelationTest.testMTMVRelation --- .../src/main/java/org/apache/doris/mtmv/MTMVRelation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java index 46caf032f53dc7..9844e10570034e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java @@ -73,7 +73,8 @@ public Set getBaseTablesOneLevelAndFromView() { } public Set getBaseViewsOneLevel() { - return baseViewsOneLevel; + // For compatibility, previously created MTMV may not have baseViewsOneLevel + return baseViewsOneLevel == null ? baseViews : baseViewsOneLevel; } public Set getBaseViews() { From f7ad3c625053b4535cab0cadb5bee45e66db2611 Mon Sep 17 00:00:00 2001 From: yujun Date: Thu, 11 Jun 2026 18:21:40 +0800 Subject: [PATCH 2/4] Use gsonPostProcess for baseViewsOneLevel backward compat Move the null-safety fallback from getBaseViewsOneLevel() to gsonPostProcess(), so the compatibility fix is applied once at deserialization time rather than on every getter call. Co-Authored-By: Claude Fable 5 --- .../java/org/apache/doris/mtmv/MTMVRelation.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java index 9844e10570034e..c1aab792f5b9e3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java @@ -18,13 +18,15 @@ package org.apache.doris.mtmv; import org.apache.doris.datasource.CatalogMgr; +import org.apache.doris.persist.gson.GsonPostProcessable; import com.google.gson.annotations.SerializedName; import org.apache.commons.collections4.CollectionUtils; +import java.io.IOException; import java.util.Set; -public class MTMVRelation { +public class MTMVRelation implements GsonPostProcessable { // t1 => v1 => v2 // t2 => mv1 // mv1 join v2 => mv2 @@ -73,14 +75,21 @@ public Set getBaseTablesOneLevelAndFromView() { } public Set getBaseViewsOneLevel() { - // For compatibility, previously created MTMV may not have baseViewsOneLevel - return baseViewsOneLevel == null ? baseViews : baseViewsOneLevel; + return baseViewsOneLevel; } public Set getBaseViews() { return baseViews; } + @Override + public void gsonPostProcess() throws IOException { + // For backward compatibility: previously created MTMV may not have baseViewsOneLevel + if (baseViewsOneLevel == null) { + baseViewsOneLevel = baseViews; + } + } + // toString() is not easy to find where to call the method public String toInfoString() { return "MTMVRelation{" From 93e14b1115c45228c00a646e39e82ef0de247dad Mon Sep 17 00:00:00 2001 From: yujun Date: Thu, 11 Jun 2026 18:24:45 +0800 Subject: [PATCH 3/4] Use copy for baseViewsOneLevel fallback in gsonPostProcess Avoid shared reference between baseViews and baseViewsOneLevel by creating a new HashSet copy. Co-Authored-By: Claude Fable 5 --- .../src/main/java/org/apache/doris/mtmv/MTMVRelation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java index c1aab792f5b9e3..6796528654d0d8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java @@ -24,6 +24,7 @@ import org.apache.commons.collections4.CollectionUtils; import java.io.IOException; +import java.util.HashSet; import java.util.Set; public class MTMVRelation implements GsonPostProcessable { @@ -86,7 +87,7 @@ public Set getBaseViews() { public void gsonPostProcess() throws IOException { // For backward compatibility: previously created MTMV may not have baseViewsOneLevel if (baseViewsOneLevel == null) { - baseViewsOneLevel = baseViews; + baseViewsOneLevel = baseViews == null ? null : new HashSet<>(baseViews); } } From 4103dd33e30b970c9ed2659838aae5dd16d155f2 Mon Sep 17 00:00:00 2001 From: yujun Date: Thu, 11 Jun 2026 18:25:39 +0800 Subject: [PATCH 4/4] Ensure baseViewsOneLevel is never null after gsonPostProcess Fall back to empty set instead of null when baseViews is also null. Co-Authored-By: Claude Fable 5 --- .../src/main/java/org/apache/doris/mtmv/MTMVRelation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java index 6796528654d0d8..452733cf7a7486 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelation.java @@ -87,7 +87,7 @@ public Set getBaseViews() { public void gsonPostProcess() throws IOException { // For backward compatibility: previously created MTMV may not have baseViewsOneLevel if (baseViewsOneLevel == null) { - baseViewsOneLevel = baseViews == null ? null : new HashSet<>(baseViews); + baseViewsOneLevel = baseViews == null ? new HashSet<>() : new HashSet<>(baseViews); } }