This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new d289395453a [fix](mtmv) Fix the old version of the materialized view
error 'Current database is not set'` (#42152) (#42309)
d289395453a is described below
commit d289395453ab22a902f824762e5fd949f6cc7637
Author: zhangdong <[email protected]>
AuthorDate: Mon Nov 11 10:27:41 2024 +0800
[fix](mtmv) Fix the old version of the materialized view error 'Current
database is not set'` (#42152) (#42309)
pick from master #42152
---
.../main/java/org/apache/doris/catalog/MTMV.java | 14 ++++++
.../main/java/org/apache/doris/mtmv/EnvInfo.java | 52 ++++++++++++++++++++++
.../java/org/apache/doris/mtmv/MTMVPlanUtil.java | 27 +++++++++++
3 files changed, 93 insertions(+)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
index 7eb47a95760..93d9a8d8dfb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
@@ -28,6 +28,7 @@ import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.datasource.CatalogMgr;
import org.apache.doris.job.common.TaskStatus;
import org.apache.doris.job.extensions.mtmv.MTMVTask;
+import org.apache.doris.mtmv.EnvInfo;
import org.apache.doris.mtmv.MTMVCache;
import org.apache.doris.mtmv.MTMVJobInfo;
import org.apache.doris.mtmv.MTMVJobManager;
@@ -73,6 +74,9 @@ public class MTMV extends OlapTable {
private String querySql;
@SerializedName("s")
private MTMVStatus status;
+ @Deprecated
+ @SerializedName("ei")
+ private EnvInfo envInfo;
@SerializedName("ji")
private MTMVJobInfo jobInfo;
@SerializedName("mp")
@@ -110,6 +114,7 @@ public class MTMV extends OlapTable {
this.mvPartitionInfo = params.mvPartitionInfo;
this.relation = params.relation;
this.refreshSnapshot = new MTMVRefreshSnapshot();
+ this.envInfo = new EnvInfo(-1L, -1L);
mvRwLock = new ReentrantReadWriteLock(true);
}
@@ -140,6 +145,10 @@ public class MTMV extends OlapTable {
}
}
+ public EnvInfo getEnvInfo() {
+ return envInfo;
+ }
+
public MTMVJobInfo getJobInfo() {
readMvLock();
try {
@@ -498,6 +507,11 @@ public class MTMV extends OlapTable {
refreshInfo = materializedView.refreshInfo;
querySql = materializedView.querySql;
status = materializedView.status;
+ if (materializedView.envInfo != null) {
+ envInfo = materializedView.envInfo;
+ } else {
+ envInfo = new EnvInfo(-1L, -1L);
+ }
jobInfo = materializedView.jobInfo;
mvProperties = materializedView.mvProperties;
relation = materializedView.relation;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java
new file mode 100644
index 00000000000..c00ae6e513e
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.mtmv;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * EnvInfo
+ */
+@Deprecated
+public class EnvInfo {
+ @SerializedName("ci")
+ private long ctlId;
+ @SerializedName("di")
+ private long dbId;
+
+ public EnvInfo(long ctlId, long dbId) {
+ this.ctlId = ctlId;
+ this.dbId = dbId;
+ }
+
+ public long getCtlId() {
+ return ctlId;
+ }
+
+ public long getDbId() {
+ return dbId;
+ }
+
+ @Override
+ public String toString() {
+ return "EnvInfo{"
+ + "ctlId='" + ctlId + '\''
+ + ", dbId='" + dbId + '\''
+ + '}';
+ }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
index 0a93af5676f..c0cd47bd5a0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
@@ -19,10 +19,12 @@ package org.apache.doris.mtmv;
import org.apache.doris.analysis.StatementBase;
import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.MTMV;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
+import org.apache.doris.datasource.CatalogIf;
import org.apache.doris.mysql.privilege.Auth;
import org.apache.doris.nereids.NereidsPlanner;
import org.apache.doris.nereids.StatementContext;
@@ -65,9 +67,34 @@ public class MTMVPlanUtil {
ctx.getSessionVariable().setWorkloadGroup(workloadGroup.get());
}
ctx.setStartTime();
+ // Set db&catalog to be used when creating materialized views to avoid
SQL statements not writing the full path
+ // After https://github.com/apache/doris/pull/36543,
+ // After 1, this logic is no longer needed. This is to be compatible
with older versions
+ setCatalogAndDb(ctx, mtmv);
return ctx;
}
+ private static void setCatalogAndDb(ConnectContext ctx, MTMV mtmv) {
+ EnvInfo envInfo = mtmv.getEnvInfo();
+ if (envInfo == null) {
+ return;
+ }
+ // switch catalog;
+ CatalogIf catalog =
Env.getCurrentEnv().getCatalogMgr().getCatalog(envInfo.getCtlId());
+ // if catalog not exist, it may not have any impact, so there is no
error and it will be returned directly
+ if (catalog == null) {
+ return;
+ }
+ ctx.changeDefaultCatalog(catalog.getName());
+ // use db
+ Optional<? extends DatabaseIf<? extends TableIf>> databaseIf =
catalog.getDb(envInfo.getDbId());
+ // if db not exist, it may not have any impact, so there is no error
and it will be returned directly
+ if (!databaseIf.isPresent()) {
+ return;
+ }
+ ctx.setDatabase(databaseIf.get().getFullName());
+ }
+
public static MTMVRelation generateMTMVRelation(MTMV mtmv, ConnectContext
ctx) {
// Should not make table without data to empty relation when analyze
the related table,
// so add disable rules
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]