You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by sc...@apache.org on 2025/03/19 10:50:44 UTC

(beam) branch master updated: add equals hashCode to BoundedToUnboundedSourceAdapter (#34057)

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

scwhittle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 50b27874291 add equals hashCode to BoundedToUnboundedSourceAdapter (#34057)
50b27874291 is described below

commit 50b278742914ab1737a597ce3835e75d3d8e8f9b
Author: Sam Whittle <sc...@users.noreply.github.com>
AuthorDate: Wed Mar 19 11:50:37 2025 +0100

    add equals hashCode to BoundedToUnboundedSourceAdapter (#34057)
---
 .../util/construction/UnboundedReadFromBoundedSource.java | 15 +++++++++++++++
 .../construction/UnboundedReadFromBoundedSourceTest.java  |  5 ++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSource.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSource.java
index 430cec0d247..7256be139e7 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSource.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSource.java
@@ -28,6 +28,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Objects;
 import java.util.stream.Collectors;
 import org.apache.beam.sdk.coders.Coder;
 import org.apache.beam.sdk.coders.CoderException;
@@ -121,6 +122,20 @@ public class UnboundedReadFromBoundedSource<T> extends PTransform<PBegin, PColle
       this.boundedSource = boundedSource;
     }
 
+    @Override
+    public boolean equals(Object other) {
+      if (!(other instanceof BoundedToUnboundedSourceAdapter)) {
+        return false;
+      }
+      return Objects.equals(
+          boundedSource, ((BoundedToUnboundedSourceAdapter<?>) other).boundedSource);
+    }
+
+    @Override
+    public int hashCode() {
+      return Objects.hash(boundedSource);
+    }
+
     @Override
     public void validate() {
       boundedSource.validate();
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSourceTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSourceTest.java
index af5a442d152..3279f66d5c6 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSourceTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSourceTest.java
@@ -18,7 +18,6 @@
 package org.apache.beam.sdk.util.construction;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -262,7 +261,7 @@ public class UnboundedReadFromBoundedSourceTest {
     PipelineOptions options = PipelineOptionsFactory.create();
     List<?> splits = unboundedCountingSource.split(100, options);
     assertEquals(1, splits.size());
-    assertNotEquals(splits.get(0), unboundedCountingSource);
+    assertEquals(splits.get(0), unboundedCountingSource);
   }
 
   @Test
@@ -272,7 +271,7 @@ public class UnboundedReadFromBoundedSourceTest {
     PipelineOptions options = PipelineOptionsFactory.create();
     List<?> splits = unboundedCountingSource.split(100, options);
     assertEquals(1, splits.size());
-    assertNotEquals(splits.get(0), unboundedCountingSource);
+    assertEquals(splits.get(0), unboundedCountingSource);
   }
 
   @Test