Skip to content

Commit 5444354

Browse files
LuciferYangdongjoon-hyun
authored andcommitted
[SPARK-53234][CORE][SQL][MLLIB][YARN] Use java.util.Objects instead of com.google.common.base.Objects
### What changes were proposed in this pull request? This pull request replaces `com.google.common.base.Objects` with `java.util.Objects`. Specifically, the following changes have been made: 1. Use `java.util.Objects#equals` instead of `com.google.common.base.Objects#equal`. 2. Use `java.util.Objects#hash` instead of `com.google.common.base.Objects#hashCode`. 3. Ban the use of `com.google.common.base.Objects`. ### Why are the changes needed? Following the recommendation in `com.google.common.base.Objects`: " https://github.com/google/guava/blob/5c71d2a15435399fa62508d807d5cc83506f7496/guava/src/com/google/common/base/Objects.java#L37-L80 ```java /** ... * * <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated; use {link * java.util.Objects#equals} instead. */ public static boolean equal(CheckForNull Object a, CheckForNull Object b) { return a == b || (a != null && a.equals(b)); } /** ... * * <p><b>Note:</b> this method is now unnecessary and should be treated as deprecated; use {link * java.util.Objects#hash} instead. */ public static int hashCode(CheckForNull Nullable Object... objects) { return Arrays.hashCode(objects); } ``` ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? - Pass GitHub Actions ### Was this patch authored or co-authored using generative AI tooling? No Closes #51960 from LuciferYang/SPARK-53234. Authored-by: yangjie01 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent f4d1012 commit 5444354

File tree

21 files changed

+71
-55
lines changed

21 files changed

+71
-55
lines changed

common/kvstore/src/main/java/org/apache/spark/util/kvstore/InMemoryStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import java.util.HashSet;
2525
import java.util.List;
2626
import java.util.NoSuchElementException;
27+
import java.util.Objects;
2728
import java.util.concurrent.ConcurrentHashMap;
2829
import java.util.concurrent.ConcurrentMap;
2930
import java.util.function.BiConsumer;
3031
import java.util.function.Predicate;
3132
import java.util.stream.Collectors;
3233
import java.util.stream.Stream;
3334

34-
import com.google.common.base.Objects;
3535
import com.google.common.base.Preconditions;
3636

3737
import org.apache.spark.annotation.Private;
@@ -70,7 +70,7 @@ public long count(Class<?> type, String index, Object indexedValue) throws Excep
7070
Object comparable = asKey(indexedValue);
7171
KVTypeInfo.Accessor accessor = list.getIndexAccessor(index);
7272
for (Object o : view(type)) {
73-
if (Objects.equal(comparable, asKey(accessor.get(o)))) {
73+
if (Objects.equals(comparable, asKey(accessor.get(o)))) {
7474
count++;
7575
}
7676
}

common/network-common/src/main/java/org/apache/spark/network/protocol/AbstractMessage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.network.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
2121

2222
import org.apache.spark.network.buffer.ManagedBuffer;
2323

@@ -48,7 +48,7 @@ public boolean isBodyInFrame() {
4848
}
4949

5050
protected boolean equals(AbstractMessage other) {
51-
return isBodyInFrame == other.isBodyInFrame && Objects.equal(body, other.body);
51+
return isBodyInFrame == other.isBodyInFrame && Objects.equals(body, other.body);
5252
}
5353

5454
}

common/network-common/src/main/java/org/apache/spark/network/protocol/MergedBlockMetaRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.apache.spark.network.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
21+
2122
import io.netty.buffer.ByteBuf;
2223

2324
/**
@@ -77,15 +78,15 @@ public static MergedBlockMetaRequest decode(ByteBuf buf) {
7778

7879
@Override
7980
public int hashCode() {
80-
return Objects.hashCode(requestId, appId, shuffleId, shuffleMergeId, reduceId);
81+
return Objects.hash(requestId, appId, shuffleId, shuffleMergeId, reduceId);
8182
}
8283

8384
@Override
8485
public boolean equals(Object other) {
8586
if (other instanceof MergedBlockMetaRequest o) {
8687
return requestId == o.requestId && shuffleId == o.shuffleId &&
8788
shuffleMergeId == o.shuffleMergeId && reduceId == o.reduceId &&
88-
Objects.equal(appId, o.appId);
89+
Objects.equals(appId, o.appId);
8990
}
9091
return false;
9192
}

common/network-common/src/main/java/org/apache/spark/network/protocol/MergedBlockMetaSuccess.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.apache.spark.network.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
21+
2122
import io.netty.buffer.ByteBuf;
2223

2324
import org.apache.spark.network.buffer.ManagedBuffer;
@@ -49,7 +50,7 @@ public Type type() {
4950

5051
@Override
5152
public int hashCode() {
52-
return Objects.hashCode(requestId, numChunks);
53+
return Objects.hash(requestId, numChunks);
5354
}
5455

5556
@Override

common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/AbstractFetchShuffleBlocks.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.apache.spark.network.shuffle.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
21+
2122
import io.netty.buffer.ByteBuf;
2223

2324
import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -63,7 +64,7 @@ public boolean equals(Object o) {
6364
if (o == null || getClass() != o.getClass()) return false;
6465
AbstractFetchShuffleBlocks that = (AbstractFetchShuffleBlocks) o;
6566
return shuffleId == that.shuffleId
66-
&& Objects.equal(appId, that.appId) && Objects.equal(execId, that.execId);
67+
&& Objects.equals(appId, that.appId) && Objects.equals(execId, that.execId);
6768
}
6869

6970
@Override

common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FinalizeShuffleMerge.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.apache.spark.network.shuffle.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
21+
2122
import io.netty.buffer.ByteBuf;
2223

2324
import org.apache.spark.network.protocol.Encoders;
@@ -52,7 +53,7 @@ protected BlockTransferMessage.Type type() {
5253

5354
@Override
5455
public int hashCode() {
55-
return Objects.hashCode(appId, appAttemptId, shuffleId, shuffleMergeId);
56+
return Objects.hash(appId, appAttemptId, shuffleId, shuffleMergeId);
5657
}
5758

5859
@Override
@@ -64,7 +65,7 @@ public String toString() {
6465
@Override
6566
public boolean equals(Object other) {
6667
if (other instanceof FinalizeShuffleMerge o) {
67-
return Objects.equal(appId, o.appId)
68+
return Objects.equals(appId, o.appId)
6869
&& appAttemptId == o.appAttemptId
6970
&& shuffleId == o.shuffleId
7071
&& shuffleMergeId == o.shuffleMergeId;

common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/MergeStatuses.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
import java.util.Arrays;
2121

22-
import com.google.common.base.Objects;
22+
import java.util.Objects;
23+
2324
import io.netty.buffer.ByteBuf;
2425
import org.roaringbitmap.RoaringBitmap;
2526

@@ -91,8 +92,8 @@ public String toString() {
9192
@Override
9293
public boolean equals(Object other) {
9394
if (other instanceof MergeStatuses o) {
94-
return Objects.equal(shuffleId, o.shuffleId)
95-
&& Objects.equal(shuffleMergeId, o.shuffleMergeId)
95+
return Objects.equals(shuffleId, o.shuffleId)
96+
&& Objects.equals(shuffleMergeId, o.shuffleMergeId)
9697
&& Arrays.equals(bitmaps, o.bitmaps)
9798
&& Arrays.equals(reduceIds, o.reduceIds)
9899
&& Arrays.equals(sizes, o.sizes);

common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/PushBlockStream.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.apache.spark.network.shuffle.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
21+
2122
import io.netty.buffer.ByteBuf;
2223

2324
import org.apache.spark.network.protocol.Encoders;
@@ -65,7 +66,7 @@ protected Type type() {
6566

6667
@Override
6768
public int hashCode() {
68-
return Objects.hashCode(appId, appAttemptId, shuffleId, shuffleMergeId, mapIndex , reduceId,
69+
return Objects.hash(appId, appAttemptId, shuffleId, shuffleMergeId, mapIndex , reduceId,
6970
index);
7071
}
7172

@@ -79,7 +80,7 @@ public String toString() {
7980
@Override
8081
public boolean equals(Object other) {
8182
if (other instanceof PushBlockStream o) {
82-
return Objects.equal(appId, o.appId)
83+
return Objects.equals(appId, o.appId)
8384
&& appAttemptId == o.appAttemptId
8485
&& shuffleId == o.shuffleId
8586
&& shuffleMergeId == o.shuffleMergeId

common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/RemoveShuffleMerge.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.apache.spark.network.shuffle.protocol;
1919

20-
import com.google.common.base.Objects;
20+
import java.util.Objects;
21+
2122
import io.netty.buffer.ByteBuf;
2223

2324
import org.apache.spark.network.protocol.Encoders;
@@ -52,7 +53,7 @@ protected Type type() {
5253

5354
@Override
5455
public int hashCode() {
55-
return Objects.hashCode(appId, appAttemptId, shuffleId, shuffleMergeId);
56+
return Objects.hash(appId, appAttemptId, shuffleId, shuffleMergeId);
5657
}
5758

5859
@Override
@@ -64,7 +65,7 @@ public String toString() {
6465
@Override
6566
public boolean equals(Object other) {
6667
if (other != null && other instanceof RemoveShuffleMerge o) {
67-
return Objects.equal(appId, o.appId)
68+
return Objects.equals(appId, o.appId)
6869
&& appAttemptId == o.appAttemptId
6970
&& shuffleId == o.shuffleId
7071
&& shuffleMergeId == o.shuffleMergeId;

core/src/main/scala/org/apache/spark/rdd/RDDOperationScope.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package org.apache.spark.rdd
1919

20+
import java.util.Objects
2021
import java.util.concurrent.atomic.AtomicInteger
2122

2223
import com.fasterxml.jackson.annotation.{JsonIgnore, JsonInclude, JsonPropertyOrder}
2324
import com.fasterxml.jackson.annotation.JsonInclude.Include
2425
import com.fasterxml.jackson.databind.ObjectMapper
2526
import com.fasterxml.jackson.module.scala.DefaultScalaModule
26-
import com.google.common.base.Objects
2727

2828
import org.apache.spark.SparkContext
2929
import org.apache.spark.internal.Logging
@@ -69,7 +69,7 @@ private[spark] class RDDOperationScope(
6969
}
7070
}
7171

72-
override def hashCode(): Int = Objects.hashCode(id, name, parent)
72+
override def hashCode(): Int = Objects.hash(id, name, parent)
7373

7474
override def toString: String = toJson
7575
}

0 commit comments

Comments
 (0)