Skip to content

Commit dc60d28

Browse files
cgivreestherbuchwalter
authored andcommitted
DRILL-8017: Fix LGTM Issues Relating to Equals and HashCode Functions (#2344)
1 parent 374db31 commit dc60d28

File tree

17 files changed

+135
-16
lines changed

17 files changed

+135
-16
lines changed

contrib/format-maprdb/src/main/java/org/apache/drill/exec/store/mapr/TableFormatPluginConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.drill.common.logical.FormatPluginConfig;
2121

2222
public abstract class TableFormatPluginConfig implements FormatPluginConfig {
23-
23+
//lgtm [java/inconsistent-equals-and-hashcode]
2424
@Override
2525
public boolean equals(Object obj) {
2626
if (this == obj) {

contrib/format-maprdb/src/main/java/org/apache/drill/exec/store/mapr/db/MapRDBFormatPluginConfig.java

+30
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,36 @@ public int hashCode() {
5353
return result;
5454
}
5555

56+
@Override
57+
public boolean equals(Object obj) {
58+
if (this == obj) {
59+
return true;
60+
} else if (obj == null || getClass() != obj.getClass()) {
61+
return false;
62+
}
63+
64+
MapRDBFormatPluginConfig other = (MapRDBFormatPluginConfig) obj;
65+
if (readAllNumbersAsDouble != other.readAllNumbersAsDouble) {
66+
return false;
67+
} else if (allTextMode != other.allTextMode) {
68+
return false;
69+
} else if (ignoreSchemaChange != other.ignoreSchemaChange) {
70+
return false;
71+
} else if (enablePushdown != other.enablePushdown) {
72+
return false;
73+
} else if (disableCountOptimization != other.disableCountOptimization) {
74+
return false;
75+
} else if (nonExistentFieldSupport != other.nonExistentFieldSupport) {
76+
return false;
77+
} else if (!index.equals(other.index)) {
78+
return false;
79+
} else if (readTimestampWithZoneOffset != other.readTimestampWithZoneOffset) {
80+
return false;
81+
}
82+
return true;
83+
}
84+
85+
5686
@Override
5787
protected boolean impEquals(Object obj) {
5888
MapRDBFormatPluginConfig other = (MapRDBFormatPluginConfig) obj;

contrib/format-maprdb/src/main/java/org/apache/drill/exec/store/mapr/db/json/JsonTableRangePartitionFunction.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.drill.exec.store.mapr.db.json;
1919

2020
import java.util.List;
21+
import java.util.Objects;
2122

2223
import org.apache.drill.common.expression.FieldReference;
2324
import org.apache.drill.exec.planner.physical.AbstractRangePartitionFunction;
@@ -106,6 +107,11 @@ public void setup(List<VectorWrapper<?>> partitionKeys) {
106107
Preconditions.checkArgument(partitionKeyVector != null, "Found null partitionKeVector.");
107108
}
108109

110+
@Override
111+
public int hashCode() {
112+
return Objects.hash(refList, tableName, userName, partitionKeyVector, startKeys, stopKeys);
113+
}
114+
109115
@Override
110116
public boolean equals(Object obj) {
111117
if (this == obj) {

contrib/format-maprdb/src/main/java/org/apache/drill/exec/store/mapr/streams/StreamsFormatPluginConfig.java

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public int hashCode() {
3131
return 47;
3232
}
3333

34+
@Override
35+
public boolean equals(Object that) {
36+
if (this == that) {
37+
return true;
38+
} else if (that == null || getClass() != that.getClass()) {
39+
return false;
40+
}
41+
return impEquals(that);
42+
}
43+
3444
@Override
3545
protected boolean impEquals(Object obj) {
3646
return true; // TODO: compare custom properties once added

contrib/storage-kafka/src/main/java/org/apache/drill/exec/store/kafka/KafkaPartitionScanSpec.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
import com.fasterxml.jackson.annotation.JsonCreator;
2323
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import org.apache.drill.common.PlanStringBuilder;
25+
26+
import java.util.Objects;
2427

2528
public class KafkaPartitionScanSpec {
2629
private final String topicName;
@@ -90,10 +93,19 @@ public boolean equals(Object obj) {
9093
return false;
9194
}
9295

96+
@Override
97+
public int hashCode() {
98+
return Objects.hash(topicName, partitionId, startOffset, endOffset);
99+
}
100+
93101
@Override
94102
public String toString() {
95-
return "KafkaPartitionScanSpec [topicName=" + topicName + ", partitionId=" + partitionId + ", startOffset="
96-
+ startOffset + ", endOffset=" + endOffset + "]";
103+
return new PlanStringBuilder(this)
104+
.field("topicName", topicName)
105+
.field("partitionId", partitionId)
106+
.field("startOffset", startOffset)
107+
.field("endOffset", endOffset)
108+
.toString();
97109
}
98110

99111
@Override

exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillCostBase.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
import org.apache.calcite.plan.RelOptCost;
2121
import org.apache.calcite.plan.RelOptUtil;
22-
import org.apache.calcite.runtime.Utilities;
22+
23+
import java.util.Objects;
2324

2425
/**
2526
* Implementation of the DrillRelOptCost, modeled similar to VolcanoCost
@@ -159,8 +160,21 @@ public double getMemory() {
159160

160161
@Override
161162
public int hashCode() {
162-
return Utilities.hashCode(rowCount) + Utilities.hashCode(cpu)
163-
+ Utilities.hashCode(io) + Utilities.hashCode(network);
163+
return Objects.hash(rowCount, cpu, io, network);
164+
}
165+
166+
@Override
167+
public boolean equals(Object that) {
168+
if (this == that) {
169+
return true;
170+
} else if (that == null || getClass() != that.getClass()) {
171+
return false;
172+
}
173+
DrillCostBase thatConfig = (DrillCostBase) that;
174+
return Objects.equals(rowCount, thatConfig.rowCount) &&
175+
Objects.equals(cpu, thatConfig.cpu) &&
176+
Objects.equals(io, thatConfig.io) &&
177+
Objects.equals(network, thatConfig.network);
164178
}
165179

166180
@Override

exec/java-exec/src/main/java/org/apache/drill/exec/planner/index/DrillIndexDefinition.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ public String toString() {
198198
public boolean equals(Object o) {
199199
if (this == o) {
200200
return true;
201-
}
202-
if (o == null) {
201+
} else if (o == null || getClass() != o.getClass()) {
203202
return false;
204203
}
204+
205205
DrillIndexDefinition index1 = (DrillIndexDefinition) o;
206206
return tableName.equals(index1.tableName)
207207
&& indexName.equals(index1.indexName)

exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/StoragePlugins.java

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Iterator;
2323
import java.util.Map;
2424
import java.util.Map.Entry;
25+
import java.util.Objects;
2526
import java.util.Optional;
2627

2728
import org.apache.drill.common.logical.StoragePluginConfig;
@@ -90,6 +91,11 @@ public boolean equals(Object obj) {
9091
return storage.equals(((StoragePlugins) obj).getStorage());
9192
}
9293

94+
@Override
95+
public int hashCode() {
96+
return Objects.hash(storage);
97+
}
98+
9399
/**
94100
* Put one plugin into current storage plugins map
95101
*

exec/java-exec/src/main/java/org/apache/drill/exec/record/DeadBuf.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ public ByteBuf asReadOnly() {
917917
}
918918

919919
@Override
920-
public boolean equals(Object arg0) {
920+
public boolean equals(Object arg0) { //lgtm [java/unchecked-cast-in-equals]
921921
return false;
922922
}
923923

exec/java-exec/src/main/java/org/apache/drill/exec/schema/Field.java

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.apache.drill.shaded.guava.com.google.common.base.MoreObjects;
2323
import org.apache.drill.shaded.guava.com.google.common.base.Strings;
2424

25+
import java.util.Objects;
26+
2527
public abstract class Field {
2628
final String prefixFieldName;
2729
MajorType fieldType;
@@ -91,6 +93,17 @@ public void setFieldType(MajorType fieldType) {
9193
this.fieldType = fieldType;
9294
}
9395

96+
@Override
97+
public boolean equals(Object that) {
98+
if (this == that) {
99+
return true;
100+
} else if (that == null || getClass() != that.getClass()) {
101+
return false;
102+
}
103+
Field thatField = (Field)that;
104+
return Objects.equals(getFullFieldName(), thatField.getFullFieldName());
105+
}
106+
94107
@Override
95108
public int hashCode() {
96109
return getFullFieldName().hashCode();

exec/java-exec/src/main/java/org/apache/drill/exec/store/log/LogFormatField.java

+5
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@ public boolean equals(Object o) {
8080
Objects.equals(fieldType, other.fieldType) &&
8181
Objects.equals(format, other.format);
8282
}
83+
84+
@Override
85+
public int hashCode() {
86+
return Objects.hash(fieldName, fieldType, format);
87+
}
8388
}

exec/vector/src/main/java/org/apache/drill/exec/record/metadata/AbstractPropertied.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void removeProperty(String key) {
120120
}
121121

122122
@Override
123-
public boolean equals(Object o) {
123+
public boolean equals(Object o) { //lgtm [java/unchecked-cast-in-equals]
124124
if (o == this) {
125125
return true;
126126
}

exec/vector/src/main/java/org/apache/drill/exec/record/metadata/TupleSchema.java

+7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
2525
import org.apache.drill.exec.record.MaterializedField;
2626

27+
2728
import java.util.ArrayList;
2829
import java.util.Iterator;
2930
import java.util.List;
3031
import java.util.Map;
32+
import java.util.Objects;
3133
import java.util.stream.Collectors;
3234

3335
/**
@@ -172,6 +174,11 @@ public boolean equals(Object o) {
172174
return isEquivalent((TupleMetadata) o);
173175
}
174176

177+
@Override
178+
public int hashCode() {
179+
return Objects.hash(parentMap, nameSpace);
180+
}
181+
175182
@Override
176183
public List<MaterializedField> toFieldList() {
177184
List<MaterializedField> cols = new ArrayList<>();

exec/vector/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.List;
22-
2322
import com.fasterxml.jackson.core.JsonProcessingException;
2423
import com.fasterxml.jackson.databind.ObjectMapper;
2524

2625
public class JsonStringArrayList<E> extends ArrayList<E> {
27-
26+
//lgtm [java/inconsistent-equals-and-hashcode]
2827
private static ObjectMapper mapper;
2928

3029
static {

exec/vector/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* toString() method of the HashMap class to produce a JSON string instead
3131
*/
3232
public class JsonStringHashMap<K, V> extends LinkedHashMap<K, V> {
33-
33+
// lgtm [java/inconsistent-equals-and-hashcode]
3434
private static final ObjectMapper mapper = new ObjectMapper()
3535
.registerModule(SerializationModule.getModule())
3636
.registerModule(new JodaModule());

logical/src/main/java/org/apache/drill/common/graph/AdjacencyList.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@
1717
*/
1818
package org.apache.drill.common.graph;
1919

20+
import org.apache.drill.shaded.guava.com.google.common.collect.ArrayListMultimap;
21+
import org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap;
22+
import org.apache.drill.shaded.guava.com.google.common.collect.Multimaps;
23+
2024
import java.util.ArrayList;
2125
import java.util.Collection;
2226
import java.util.Collections;
2327
import java.util.HashSet;
2428
import java.util.Iterator;
2529
import java.util.LinkedList;
2630
import java.util.List;
31+
import java.util.Objects;
2732
import java.util.Set;
2833

29-
import org.apache.drill.shaded.guava.com.google.common.collect.ArrayListMultimap;
30-
import org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap;
31-
import org.apache.drill.shaded.guava.com.google.common.collect.Multimaps;
3234

3335
class AdjacencyList<V extends GraphValue<V>> {
3436
private Set<Node> allNodes = new HashSet<Node>();
@@ -167,6 +169,16 @@ public int hashCode() {
167169
return nodeValue.hashCode();
168170
}
169171

172+
@Override
173+
public boolean equals(Object that) {
174+
if (this == that) {
175+
return true;
176+
} else if (that == null || getClass() != that.getClass()) {
177+
return false;
178+
}
179+
return Objects.equals(nodeValue, ((Node) that).getNodeValue());
180+
}
181+
170182
public V getNodeValue() {
171183
return nodeValue;
172184
}

logical/src/main/java/org/apache/drill/common/logical/data/LogicalOperatorBase.java

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public final int hashCode() {
4040
return super.hashCode();
4141
}
4242

43+
@Override
44+
public boolean equals(Object obj) {
45+
return super.equals(obj);
46+
}
47+
4348
@Override
4449
public void setupAndValidate(List<LogicalOperator> operators, Collection<ValidationError> errors) {
4550
// TODO: remove this and implement individually.

0 commit comments

Comments
 (0)