This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 50a4700e98 [core] Compare IcebergRef by value (#9405)
50a4700e98 is described below
commit 50a4700e986056fcfa9e642b344e2ed05f13274d
Author: ZIHAN DAI <[email protected]>
AuthorDate: Thu Aug 27 17:08:49 2026 +1000
[core] Compare IcebergRef by value (#9405)
---
.../apache/paimon/iceberg/metadata/IcebergRef.java | 4 +-
.../paimon/iceberg/metadata/IcebergRefTest.java | 69 ++++++++++++++++++++++
2 files changed, 71 insertions(+), 2 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergRef.java
b/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergRef.java
index c0a1cb227f..de8094001e 100644
---
a/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergRef.java
+++
b/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergRef.java
@@ -83,8 +83,8 @@ public class IcebergRef {
}
IcebergRef that = (IcebergRef) o;
return snapshotId == that.snapshotId
- && type.equals(that.type)
- && maxRefAgeMs == that.maxRefAgeMs;
+ && Objects.equals(type, that.type)
+ && Objects.equals(maxRefAgeMs, that.maxRefAgeMs);
}
@Override
diff --git
a/paimon-core/src/test/java/org/apache/paimon/iceberg/metadata/IcebergRefTest.java
b/paimon-core/src/test/java/org/apache/paimon/iceberg/metadata/IcebergRefTest.java
new file mode 100644
index 0000000000..b51376d1f5
--- /dev/null
+++
b/paimon-core/src/test/java/org/apache/paimon/iceberg/metadata/IcebergRefTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.paimon.iceberg.metadata;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link IcebergRef}. */
+public class IcebergRefTest {
+
+ @Test
+ public void testEqualsIsByValue() {
+ IcebergRef one = new IcebergRef(1L);
+ IcebergRef same = new IcebergRef(1L);
+ IcebergRef other = new IcebergRef(2L);
+
+ assertThat(one).isEqualTo(same);
+ assertThat(one).isNotEqualTo(other);
+ }
+
+ @Test
+ public void testEqualObjectsShareAHashCode() {
+ // hashCode already used value semantics, so the two disagreed: refs
that hash
+ // alike compared unequal.
+ IcebergRef one = new IcebergRef(1L);
+ IcebergRef same = new IcebergRef(1L);
+
+ assertThat(one.hashCode()).isEqualTo(same.hashCode());
+
+ Set<IcebergRef> set = new HashSet<>();
+ set.add(one);
+ set.add(same);
+ assertThat(set).hasSize(1);
+ }
+
+ @Test
+ public void testMetadataComparesItsRefsByValue() {
+ // IcebergMetadata#equals compares refs with Objects.equals over the
map, so a
+ // broken element equals propagates all the way up.
+ Map<String, IcebergRef> left = new HashMap<>();
+ left.put("tag", new IcebergRef(1L));
+ Map<String, IcebergRef> right = new HashMap<>();
+ right.put("tag", new IcebergRef(1L));
+
+ assertThat(left).isEqualTo(right);
+ }
+}