You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by hu...@apache.org on 2026/04/16 03:09:43 UTC

(iceberg) branch main updated: Core: Fix StructLikeWrapper.equals exception with mismatched partition types (#15945)

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

huaxingao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 0babf7d171 Core: Fix StructLikeWrapper.equals exception with mismatched partition types (#15945)
0babf7d171 is described below

commit 0babf7d171d45fd0b2ab7de55f5002c2fbe0cf61
Author: Yuya Ebihara <eb...@gmail.com>
AuthorDate: Thu Apr 16 12:09:36 2026 +0900

    Core: Fix StructLikeWrapper.equals exception with mismatched partition types (#15945)
---
 .../org/apache/iceberg/util/StructLikeWrapper.java |  8 +++-
 .../apache/iceberg/util/TestStructLikeWrapper.java | 47 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/iceberg/util/StructLikeWrapper.java b/core/src/main/java/org/apache/iceberg/util/StructLikeWrapper.java
index 28629706bf..2e71d24191 100644
--- a/core/src/main/java/org/apache/iceberg/util/StructLikeWrapper.java
+++ b/core/src/main/java/org/apache/iceberg/util/StructLikeWrapper.java
@@ -88,7 +88,13 @@ public class StructLikeWrapper {
       return false;
     }
 
-    return comparator.compare(this.struct, that.struct) == 0;
+    try {
+      return comparator.compare(this.struct, that.struct) == 0;
+    } catch (RuntimeException e) {
+      // An exception may occur, for example, when struct is PartitionData and its type does not
+      // match its data.
+      return false;
+    }
   }
 
   @Override
diff --git a/core/src/test/java/org/apache/iceberg/util/TestStructLikeWrapper.java b/core/src/test/java/org/apache/iceberg/util/TestStructLikeWrapper.java
new file mode 100644
index 0000000000..9eaa45c85a
--- /dev/null
+++ b/core/src/test/java/org/apache/iceberg/util/TestStructLikeWrapper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.iceberg.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.iceberg.PartitionData;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestStructLikeWrapper {
+  @Test
+  public void equalsTypeAndDataMismatch() {
+    Types.StructType intType =
+        Types.StructType.of(Types.NestedField.required(1, "a", Types.IntegerType.get()));
+    Types.StructType stringType =
+        Types.StructType.of(Types.NestedField.required(1, "a", Types.StringType.get()));
+
+    PartitionData intData = new PartitionData(intType);
+    intData.set(0, 1);
+
+    PartitionData stringData = new PartitionData(stringType);
+    stringData.set(0, "test");
+
+    StructLikeWrapper integerStruct = StructLikeWrapper.forType(intType).set(intData);
+    StructLikeWrapper stringStruct = StructLikeWrapper.forType(stringType).set(stringData);
+
+    // StructLikeWrapper.equals previously threw an exception when the type and data mismatch
+    assertThat(integerStruct).isNotEqualTo(stringStruct);
+  }
+}