branch-2.1: [fix])(catalog)add equals for external table #47956 (#48533)

Cherry-picked from https://github.com/apache/doris/pull/47956
This commit is contained in:
zhangdong
2025-03-03 18:28:43 +08:00
committed by GitHub
parent 9cf3b4671d
commit 107f4d48bd
4 changed files with 107 additions and 0 deletions

View File

@ -63,6 +63,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;
@ -1100,4 +1101,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);
}
}

View File

@ -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;
@ -759,4 +760,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);
}
}

View File

@ -41,6 +41,7 @@ import org.apache.doris.statistics.TableStatsMeta;
import org.apache.doris.statistics.util.StatisticsUtil;
import org.apache.doris.thrift.TTableDescriptor;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
@ -450,4 +451,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);
}
}

View File

@ -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);
}
}