kbendick commented on code in PR #4668:
URL: https://github.com/apache/iceberg/pull/4668#discussion_r861456057


##########
core/src/test/java/org/apache/iceberg/TestMetadataUpdateParser.java:
##########
@@ -197,4 +315,55 @@ private static void assertEqualsSetDefaultPartitionSpec(
       MetadataUpdate.SetDefaultPartitionSpec expected, 
MetadataUpdate.SetDefaultPartitionSpec actual) {
     Assertions.assertThat(actual.specId()).isEqualTo(expected.specId());
   }
+
+  private static void assertEqualsAddPartitionSpec(
+      MetadataUpdate.AddPartitionSpec expected, 
MetadataUpdate.AddPartitionSpec actual) {
+    Assert.assertEquals("Unbound partition specs should have the same spec id",
+        expected.spec().specId(), actual.spec().specId());
+    Assert.assertEquals("Unbound partition specs should have the same number 
of fields",
+        expected.spec().fields().size(), actual.spec().fields().size());
+
+    // Sort the fields so that we can compare them field by field
+    
expected.spec().fields().sort(Comparator.comparing(UnboundPartitionSpec.UnboundPartitionField::transformAsString));
+    
actual.spec().fields().sort(Comparator.comparing(UnboundPartitionSpec.UnboundPartitionField::transformAsString));
+    IntStream.range(0, expected.spec().fields().size())
+        .forEachOrdered(i -> {
+            UnboundPartitionSpec.UnboundPartitionField expectedField = 
expected.spec().fields().get(i);
+            UnboundPartitionSpec.UnboundPartitionField actualField = 
actual.spec().fields().get(i);
+            Assert.assertTrue(
+                "Fields of the unbound partition spec should be the same",
+                Objects.equals(expectedField.partitionId(), 
actualField.partitionId()) &&
+                    expectedField.name().equals(actualField.name()) &&
+                    Objects.equals(expectedField.transformAsString(), 
actualField.transformAsString()) &&
+                    expectedField.sourceId() == actualField.sourceId());
+        });
+  }
+
+  private static void assertEqualsAddSortOrder(
+      MetadataUpdate.AddSortOrder expected, MetadataUpdate.AddSortOrder 
actual) {
+    UnboundSortOrder expectedSortOrder = expected.sortOrder();
+    UnboundSortOrder actualSortOrder = actual.sortOrder();
+    Assert.assertEquals("Order id of the sort order should be the same",
+        expected.sortOrder().orderId(), actual.sortOrder().orderId());
+
+    Assert.assertEquals("Sort orders should have the same number of fields",
+        expected.sortOrder().fields().size(), 
actual.sortOrder().fields().size());
+
+    // Sort fields to compare
+    Comparator<UnboundSortOrder.UnboundSortField> comparator = Comparator
+        .comparing(UnboundSortOrder.UnboundSortField::sourceId)
+            
.thenComparing(UnboundSortOrder.UnboundSortField::transformAsString);
+    expected.sortOrder().fields().sort(comparator);
+    actual.sortOrder().fields().sort(comparator);
+    IntStream.range(0, expected.sortOrder().fields().size())
+        .forEachOrdered(i -> {
+            UnboundSortOrder.UnboundSortField expectedField = 
expected.sortOrder().fields().get(i);
+            UnboundSortOrder.UnboundSortField actualField = 
actual.sortOrder().fields().get(i);
+            Assert.assertTrue("Fields of the sort order should be the same",
+                expectedField.sourceId() == actualField.sourceId() &&
+                expectedField.nullOrder().equals(actualField.nullOrder()) &&
+                expectedField.direction().equals(actualField.direction()) &&
+                Objects.equals(expectedField.transformAsString(), 
actualField.transformAsString()));
+        });

Review Comment:
   Same note as above about potnetially adding `equals` to `UnboundSortField`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to