[refactor](planner): refactor equals code in Catalog dir. (#11903)

This commit is contained in:
jakevin
2022-08-21 10:01:57 +08:00
committed by GitHub
parent d4749c2652
commit c2efa9c3b5
16 changed files with 193 additions and 215 deletions

View File

@ -28,6 +28,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
public class DataSortInfo implements Writable {
public static final String DATA_SORT_PROPERTY_PREFIX = "data_sort";
@ -86,14 +87,21 @@ public class DataSortInfo implements Writable {
return GsonUtils.GSON.fromJson(json, DataSortInfo.class);
}
public boolean equals(DataSortInfo dataSortInfo) {
if (this.sortType != dataSortInfo.sortType) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (this.colNum != dataSortInfo.colNum) {
return false;
}
return true;
DataSortInfo that = (DataSortInfo) o;
return colNum == that.colNum && sortType == that.sortType;
}
@Override
public int hashCode() {
return Objects.hash(sortType, colNum);
}
public String toSql() {

View File

@ -565,8 +565,8 @@ public class Column implements Writable {
@Override
public int hashCode() {
return Objects.hash(name, getDataType(), aggregationType, isAggregationTypeImplicit, isKey, isAllowNull,
getDefaultValue(), getStrLen(), getPrecision(), getScale(), comment, visible, children);
return Objects.hash(name, getDataType(), getStrLen(), getPrecision(), getScale(), aggregationType,
isAggregationTypeImplicit, isKey, isAllowNull, defaultValue, comment, children, visible);
}
@Override
@ -580,62 +580,20 @@ public class Column implements Writable {
Column other = (Column) obj;
if (!this.name.equalsIgnoreCase(other.getName())) {
return false;
}
if (this.getDataType() != other.getDataType()) {
return false;
}
if (this.aggregationType != other.getAggregationType()) {
return false;
}
if (this.isAggregationTypeImplicit != other.isAggregationTypeImplicit()) {
return false;
}
if (this.isKey != other.isKey()) {
return false;
}
if (this.isAllowNull != other.isAllowNull) {
return false;
}
if (this.getDefaultValue() == null) {
if (other.getDefaultValue() != null) {
return false;
}
} else {
if (!this.getDefaultValue().equals(other.getDefaultValue())) {
return false;
}
}
if (this.getStrLen() != other.getStrLen()) {
return false;
}
if (this.getPrecision() != other.getPrecision()) {
return false;
}
if (this.getScale() != other.getScale()) {
return false;
}
if (!comment.equals(other.getComment())) {
return false;
}
if (!visible == other.visible) {
return false;
}
if (children.size() != other.children.size()) {
return false;
}
for (int i = 0; i < children.size(); i++) {
if (!children.get(i).equals(other.getChildren().get(i))) {
return false;
}
}
return true;
return name.equalsIgnoreCase(other.name)
&& Objects.equals(getDefaultValue(), other.getDefaultValue())
&& Objects.equals(aggregationType, other.aggregationType)
&& isAggregationTypeImplicit == other.isAggregationTypeImplicit
&& isKey == other.isKey
&& isAllowNull == other.isAllowNull
&& getDataType().equals(other.getDataType())
&& getStrLen() == other.getStrLen()
&& getPrecision() == other.getPrecision()
&& getScale() == other.getScale()
&& comment.equals(other.comment)
&& visible == other.visible
&& children.size() == other.children.size()
&& children.equals(other.children);
}
@Override
@ -676,8 +634,6 @@ public class Column implements Writable {
StringBuilder sb = new StringBuilder(name);
switch (dataType) {
case CHAR:
sb.append(String.format(typeStringMap.get(dataType), getStrLen()));
break;
case VARCHAR:
sb.append(String.format(typeStringMap.get(dataType), getStrLen()));
break;
@ -688,11 +644,7 @@ public class Column implements Writable {
sb.append(String.format(typeStringMap.get(dataType), getPrecision(), getScale()));
break;
case ARRAY:
sb.append(type.toString());
break;
case MAP:
sb.append(type.toString());
break;
case STRUCT:
sb.append(type.toString());
break;

View File

@ -411,7 +411,7 @@ public class Database extends MetaObject implements Writable, DatabaseIf<Table>
}
/**
* this method is used for get existed table list by table id list, if table not exist, just ignore it.
* this method is used for get existed table list by table id list, if table not exist, just ignore it.
*/
public List<Table> getTablesOnIdOrderIfExist(List<Long> tableIdList) {
List<Table> tableList = Lists.newArrayListWithCapacity(tableIdList.size());
@ -614,25 +614,12 @@ public class Database extends MetaObject implements Writable, DatabaseIf<Table>
return false;
}
Database database = (Database) obj;
Database other = (Database) obj;
if (idToTable != database.idToTable) {
if (idToTable.size() != database.idToTable.size()) {
return false;
}
for (Entry<Long, Table> entry : idToTable.entrySet()) {
long key = entry.getKey();
if (!database.idToTable.containsKey(key)) {
return false;
}
if (!entry.getValue().equals(database.idToTable.get(key))) {
return false;
}
}
}
return (id == database.id) && (fullQualifiedName.equals(database.fullQualifiedName)
&& dataQuotaBytes == database.dataQuotaBytes);
return id == other.id
&& idToTable.equals(other.idToTable)
&& fullQualifiedName.equals(other.fullQualifiedName)
&& dataQuotaBytes == other.dataQuotaBytes;
}
public String getClusterName() {

View File

@ -27,6 +27,7 @@ import org.apache.commons.lang.NotImplementedException;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;
public abstract class DistributionInfo implements Writable {
@ -36,8 +37,6 @@ public abstract class DistributionInfo implements Writable {
}
// for Gson runtime type adaptor
@SerializedName(value = "typeStr")
protected String typeStr;
@SerializedName(value = "type")
protected DistributionInfoType type;
@ -47,7 +46,6 @@ public abstract class DistributionInfo implements Writable {
public DistributionInfo(DistributionInfoType type) {
this.type = type;
this.typeStr = this.type.name();
}
public DistributionInfoType getType() {
@ -81,7 +79,20 @@ public abstract class DistributionInfo implements Writable {
return "";
}
public boolean equals(DistributionInfo info) {
return false;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DistributionInfo that = (DistributionInfo) o;
return type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(type);
}
}

View File

@ -87,13 +87,10 @@ public class FsBroker implements Writable, Comparable<FsBroker> {
return false;
}
FsBroker that = (FsBroker) o;
if (port != that.port) {
return false;
}
return ip.equals(that.ip);
FsBroker other = (FsBroker) o;
return port == other.port
&& ip.equals(other.ip);
}
@Override

View File

@ -29,6 +29,7 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Hash Distribution Info.
@ -90,20 +91,24 @@ public class HashDistributionInfo extends DistributionInfo {
return distributionInfo;
}
public boolean equals(DistributionInfo info) {
if (this == info) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(info instanceof HashDistributionInfo)) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
HashDistributionInfo that = (HashDistributionInfo) o;
return bucketNum == that.bucketNum && Objects.equals(distributionColumns, that.distributionColumns);
}
HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) info;
return type == hashDistributionInfo.type
&& bucketNum == hashDistributionInfo.bucketNum
&& distributionColumns.equals(hashDistributionInfo.distributionColumns);
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), distributionColumns, bucketNum);
}
@Override

View File

@ -28,7 +28,7 @@ import java.util.List;
public class ListPartitionItem extends PartitionItem {
public static ListPartitionItem DUMMY_ITEM = new ListPartitionItem(Lists.newArrayList());
private List<PartitionKey> partitionKeys;
private final List<PartitionKey> partitionKeys;
public ListPartitionItem(List<PartitionKey> partitionKeys) {
this.partitionKeys = partitionKeys;
@ -91,20 +91,10 @@ public class ListPartitionItem extends PartitionItem {
return false;
}
ListPartitionItem partitionItem = (ListPartitionItem) obj;
ListPartitionItem other = (ListPartitionItem) obj;
// check keys
if (partitionKeys != partitionItem.getItems()) {
if (partitionKeys.size() != partitionItem.getItems().size()) {
return false;
}
for (int i = 0; i < partitionKeys.size(); i++) {
if (!partitionKeys.get(i).equals(partitionItem.getItems().get(i))) {
return false;
}
}
}
return true;
return partitionKeys.size() == other.partitionKeys.size()
&& partitionKeys.equals(other.partitionKeys);
}
@Override

View File

@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* The OlapTraditional table is a materialized table which stored as rowcolumnar file or columnar file
@ -252,27 +251,13 @@ public class MaterializedIndex extends MetaObject implements Writable, GsonPostP
return false;
}
MaterializedIndex table = (MaterializedIndex) obj;
MaterializedIndex other = (MaterializedIndex) obj;
// Check idToTablets
if (table.idToTablets == null) {
return false;
}
if (idToTablets.size() != table.idToTablets.size()) {
return false;
}
for (Entry<Long, Tablet> entry : idToTablets.entrySet()) {
long key = entry.getKey();
if (!table.idToTablets.containsKey(key)) {
return false;
}
if (!entry.getValue().equals(table.idToTablets.get(key))) {
return false;
}
}
return (state.equals(table.state))
&& (rowCount == table.rowCount);
return other.idToTablets != null
&& idToTablets.size() == other.idToTablets.size()
&& idToTablets.equals(other.idToTablets)
&& (state.equals(other.state))
&& (rowCount == other.rowCount);
}
@Override

View File

@ -165,32 +165,17 @@ public class MaterializedIndexMeta implements Writable, GsonPostProcessable {
if (!(obj instanceof MaterializedIndexMeta)) {
return false;
}
MaterializedIndexMeta indexMeta = (MaterializedIndexMeta) obj;
if (indexMeta.indexId != this.indexId) {
return false;
}
if (indexMeta.schema.size() != this.schema.size() || !indexMeta.schema.containsAll(this.schema)) {
return false;
}
if (indexMeta.schemaVersion != this.schemaVersion) {
return false;
}
if (indexMeta.schemaHash != this.schemaHash) {
return false;
}
if (indexMeta.shortKeyColumnCount != this.shortKeyColumnCount) {
return false;
}
if (indexMeta.storageType != this.storageType) {
return false;
}
if (indexMeta.keysType != this.keysType) {
return false;
}
if (maxColUniqueId != maxColUniqueId) {
return false;
}
return true;
MaterializedIndexMeta other = (MaterializedIndexMeta) obj;
return indexId == other.indexId
&& schema.size() == other.schema.size()
&& schema.equals(other.schema)
&& schemaVersion == other.schemaVersion
&& schemaHash == other.schemaHash
&& shortKeyColumnCount == other.shortKeyColumnCount
&& storageType == other.storageType
&& keysType == other.keysType
&& maxColUniqueId == other.maxColUniqueId;
}
@Override

View File

@ -75,6 +75,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@ -1126,7 +1127,7 @@ public class OlapTable extends Table {
out.writeDouble(bfFpp);
}
//colocateTable
// colocateTable
if (colocateGroup == null) {
out.writeBoolean(false);
} else {
@ -1251,14 +1252,6 @@ public class OlapTable extends Table {
rebuildFullSchema();
}
@Override
public boolean equals(Table table) {
if (this == table) {
return true;
}
return table instanceof OlapTable;
}
public OlapTable selectiveCopy(Collection<String> reservedPartitions, IndexExtState extState, boolean isForBackup) {
OlapTable copied = new OlapTable();
if (!DeepCopy.copy(this, copied, OlapTable.class, FeConstants.meta_version)) {
@ -1489,6 +1482,39 @@ public class OlapTable extends Table {
return getSchemaByIndexId(baseIndexId, full);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OlapTable other = (OlapTable) o;
if (!Objects.equals(defaultDistributionInfo, other.defaultDistributionInfo)) {
return false;
}
return Double.compare(other.bfFpp, bfFpp) == 0 && hasSequenceCol == other.hasSequenceCol
&& baseIndexId == other.baseIndexId && state == other.state && Objects.equals(indexIdToMeta,
other.indexIdToMeta) && Objects.equals(indexNameToId, other.indexNameToId) && keysType == other.keysType
&& Objects.equals(partitionInfo, other.partitionInfo) && Objects.equals(
idToPartition, other.idToPartition) && Objects.equals(nameToPartition,
other.nameToPartition) && Objects.equals(tempPartitions, other.tempPartitions)
&& Objects.equals(bfColumns, other.bfColumns) && Objects.equals(colocateGroup,
other.colocateGroup) && Objects.equals(sequenceType, other.sequenceType)
&& Objects.equals(indexes, other.indexes) && Objects.equals(tableProperty,
other.tableProperty);
}
@Override
public int hashCode() {
return Objects.hash(state, indexIdToMeta, indexNameToId, keysType, partitionInfo, idToPartition,
nameToPartition, defaultDistributionInfo, tempPartitions, bfColumns, bfFpp, colocateGroup,
hasSequenceCol, sequenceType, indexes, baseIndexId, tableProperty);
}
public Column getBaseColumn(String columnName) {
for (Column column : getBaseSchema()) {
if (column.getName().equalsIgnoreCase(columnName)) {
@ -1884,7 +1910,7 @@ public class OlapTable extends Table {
tableProperty.buildReplicaAllocation();
}
//for light schema change
// for light schema change
public void initSchemaColumnUniqueId() {
if (!getEnableLightSchemaChange()) {
return;

View File

@ -36,7 +36,7 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
/**
* Internal representation of partition-related metadata.
@ -383,25 +383,17 @@ public class Partition extends MetaObject implements Writable {
return false;
}
Partition partition = (Partition) obj;
if (idToVisibleRollupIndex != partition.idToVisibleRollupIndex) {
if (idToVisibleRollupIndex.size() != partition.idToVisibleRollupIndex.size()) {
return false;
}
for (Entry<Long, MaterializedIndex> entry : idToVisibleRollupIndex.entrySet()) {
long key = entry.getKey();
if (!partition.idToVisibleRollupIndex.containsKey(key)) {
return false;
}
if (!entry.getValue().equals(partition.idToVisibleRollupIndex.get(key))) {
return false;
}
}
}
Partition other = (Partition) obj;
return (visibleVersion == partition.visibleVersion)
&& (baseIndex.equals(partition.baseIndex)
&& distributionInfo.equals(partition.distributionInfo));
return (visibleVersion == other.visibleVersion)
&& baseIndex.equals(other.baseIndex)
&& distributionInfo.equals(other.distributionInfo)
&& idToVisibleRollupIndex.equals(other.idToVisibleRollupIndex);
}
@Override
public int hashCode() {
return Objects.hash(visibleVersion, baseIndex, idToVisibleRollupIndex, distributionInfo);
}
@Override

View File

@ -38,6 +38,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/*
@ -376,4 +377,26 @@ public class PartitionInfo implements Writable {
return buff.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PartitionInfo that = (PartitionInfo) o;
return isMultiColumnPartition == that.isMultiColumnPartition && type == that.type && Objects.equals(
partitionColumns, that.partitionColumns) && Objects.equals(idToItem, that.idToItem)
&& Objects.equals(idToTempItem, that.idToTempItem) && Objects.equals(idToDataProperty,
that.idToDataProperty) && Objects.equals(idToStoragePolicy, that.idToStoragePolicy)
&& Objects.equals(idToReplicaAllocation, that.idToReplicaAllocation) && Objects.equals(
idToInMemory, that.idToInMemory) && Objects.equals(idToTabletType, that.idToTabletType);
}
@Override
public int hashCode() {
return Objects.hash(type, partitionColumns, idToItem, idToTempItem, idToDataProperty, idToStoragePolicy,
idToReplicaAllocation, isMultiColumnPartition, idToInMemory, idToTabletType);
}
}

View File

@ -23,6 +23,7 @@ import org.apache.doris.analysis.RandomDistributionDesc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;
/**
* Random partition.
@ -74,18 +75,23 @@ public class RandomDistributionInfo extends DistributionInfo {
return distributionInfo;
}
public boolean equals(DistributionInfo info) {
if (this == info) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(info instanceof RandomDistributionInfo)) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
RandomDistributionInfo that = (RandomDistributionInfo) o;
return bucketNum == that.bucketNum;
}
RandomDistributionInfo randomDistributionInfo = (RandomDistributionInfo) info;
return type == randomDistributionInfo.type
&& bucketNum == randomDistributionInfo.bucketNum;
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), bucketNum);
}
}

View File

@ -389,10 +389,6 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
this.createTime = in.readLong();
}
public boolean equals(Table table) {
return true;
}
// return if this table is partitioned.
// For OlapTable ture when is partitioned, or distributed by hash when no partition
public boolean isPartitioned() {

View File

@ -33,6 +33,7 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
// This class saved all temp partitions of a table.
@ -155,4 +156,22 @@ public class TempPartitions implements Writable, GsonPostProcessable {
nameToPartition.put(partition.getName(), partition);
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TempPartitions that = (TempPartitions) o;
return idToPartition.equals(that.idToPartition) && nameToPartition.equals(that.nameToPartition)
&& Objects.equals(partitionInfo, that.partitionInfo);
}
@Override
public int hashCode() {
return Objects.hash(idToPartition, nameToPartition, partitionInfo);
}
}

View File

@ -215,10 +215,6 @@ public class PartitionRange {
date = key.date;
}
public boolean equals(PartitionKeyType key) {
return realValue() == key.realValue();
}
public void add(int num) {
if (keyType == KeyType.DATE) {
date = new Date(date.getTime() + num * 3600 * 24 * 1000);