This is an automated email from the ASF dual-hosted git repository. morningman 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 2717e23cfdf [fix])(catalog)add equals for external table (#47956) 2717e23cfdf is described below commit 2717e23cfdfafd342e6f2c77464fc3ceacec34e2 Author: zhangdong <zhangd...@selectdb.com> AuthorDate: Tue Feb 25 16:44:00 2025 +0800 [fix])(catalog)add equals for external table (#47956) ### What problem does this PR solve? The materialized view is created based on external table, and sometimes refreshing the materialized view may report that the corresponding partition cannot be found. The reason is that when the materialized view is refreshed, predicates are generated based on the refreshed partition, and the problematic plan does not include predicates. The code for adding predicates is as follows: ``` if (predicates.getPredicates().containsKey(table)) { return new LogicalFilter<>(ImmutableSet.of(ExpressionUtils.or(predicates.getPredicates().get(table))), unboundRelation); } ``` If the table and predicates. get() are not the same object when setting predicates, it will not be obtained, resulting in the absence of predicates PS: The table cache will refresh within 24 hours by default, and the objects will change --- .../apache/doris/datasource/ExternalCatalog.java | 18 ++++++++ .../apache/doris/datasource/ExternalDatabase.java | 19 ++++++++ .../org/apache/doris/datasource/ExternalTable.java | 18 ++++++++ .../doris/datasource/ExternalEqualsTest.java | 52 ++++++++++++++++++++++ 4 files changed, 107 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java index 9b1d26e3647..071accf0e77 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java @@ -70,6 +70,7 @@ import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.MasterCatalogExecutor; import org.apache.doris.transaction.TransactionManager; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Lists; @@ -1178,4 +1179,21 @@ public abstract class ExternalCatalog public PreExecutionAuthenticator getPreExecutionAuthenticator() { return preExecutionAuthenticator; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ExternalCatalog)) { + return false; + } + ExternalCatalog that = (ExternalCatalog) o; + return Objects.equal(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java index 6b003f68b5c..18dce23a2db 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java @@ -43,6 +43,7 @@ import org.apache.doris.persist.gson.GsonUtils; import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.MasterCatalogExecutor; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Lists; @@ -750,4 +751,22 @@ public abstract class ExternalDatabase<T extends ExternalTable> // it needs to be judged together with Env.isTableNamesCaseInsensitive() return Env.isTableNamesCaseInsensitive() || extCatalog.getOnlyTestLowerCaseTableNames() == 2; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ExternalDatabase)) { + return false; + } + ExternalDatabase<?> that = (ExternalDatabase<?>) o; + return Objects.equal(name, that.name) && Objects.equal(extCatalog, + that.extCatalog); + } + + @Override + public int hashCode() { + return Objects.hashCode(name, extCatalog); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalTable.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalTable.java index b78d3f0dc65..30bf48c3d8b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalTable.java @@ -42,6 +42,7 @@ import org.apache.doris.statistics.ColumnStatistic; import org.apache.doris.statistics.util.StatisticsUtil; import org.apache.doris.thrift.TTableDescriptor; +import com.google.common.base.Objects; import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; import lombok.Getter; @@ -448,4 +449,21 @@ public class ExternalTable implements TableIf, Writable, GsonPostProcessable { public boolean supportInternalPartitionPruned() { return false; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ExternalTable)) { + return false; + } + ExternalTable that = (ExternalTable) o; + return Objects.equal(name, that.name) && Objects.equal(db, that.db); + } + + @Override + public int hashCode() { + return Objects.hashCode(name, db); + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalEqualsTest.java b/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalEqualsTest.java new file mode 100644 index 00000000000..fa46141075a --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalEqualsTest.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.datasource; + +import org.apache.doris.datasource.test.TestExternalCatalog; +import org.apache.doris.datasource.test.TestExternalDatabase; +import org.apache.doris.datasource.test.TestExternalTable; + +import mockit.Mocked; +import org.junit.Assert; +import org.junit.Test; + +public class ExternalEqualsTest { + @Mocked + private TestExternalCatalog ctl1; + @Mocked + private TestExternalCatalog ctl2; + + @Test + public void testEquals() { + TestExternalDatabase db1 = new TestExternalDatabase(ctl1, 1L, "db1", null); + TestExternalDatabase db2 = new TestExternalDatabase(ctl2, 1L, "db2", null); + TestExternalDatabase db3 = new TestExternalDatabase(ctl1, 1L, "db2", null); + TestExternalDatabase db11 = new TestExternalDatabase(ctl1, 1L, "db1", null); + Assert.assertNotEquals(db1, db2); + Assert.assertNotEquals(db1, db3); + Assert.assertEquals(db1, db11); + + TestExternalTable t1 = new TestExternalTable(1L, "t1", null, ctl1, db1); + TestExternalTable t2 = new TestExternalTable(2L, "t2", null, ctl2, db2); + TestExternalTable t3 = new TestExternalTable(3L, "t3", null, ctl1, db1); + TestExternalTable t11 = new TestExternalTable(4L, "t1", null, ctl1, db1); + Assert.assertNotEquals(t1, t2); + Assert.assertNotEquals(t1, t3); + Assert.assertEquals(t1, t11); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org