This is an automated email from the ASF dual-hosted git repository.

dataroaring 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 2edecb87531 branch-3.0: [fix])(catalog)add equals for external table 
#47956 (#48348)
2edecb87531 is described below

commit 2edecb875313a8bf528798a0dff63022c5f35a2c
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Mar 10 17:29:23 2025 +0800

    branch-3.0: [fix])(catalog)add equals for external table #47956 (#48348)
    
    Cherry-picked from #47956
    
    Co-authored-by: zhangdong <zhangd...@selectdb.com>
---
 .../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 d315373eca0..0b6124591da 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
@@ -65,6 +65,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;
@@ -1112,4 +1113,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

Reply via email to