sjs004 commented on code in PR #18645:
URL: https://github.com/apache/iceberg/pull/18645#discussion_r4404111759


##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestFilteredScan.java:
##########
@@ -637,24 +638,24 @@ private static Record projectFlat(Schema projection, 
Record record) {
     return result;
   }
 
-  public static void assertEqualsUnsafe(
-      Types.StructType struct, List<Record> expected, List<UnsafeRow> actual) {
-    // TODO: match records by ID
-    int numRecords = Math.min(expected.size(), actual.size());
-    for (int i = 0; i < numRecords; i += 1) {
-      GenericsHelpers.assertEqualsUnsafe(struct, expected.get(i), 
actual.get(i));
-    }
-    assertThat(actual).as("Number of results should match 
expected").hasSameSizeAs(expected);
-  }
-
   public static void assertEqualsSafe(
       Types.StructType struct, List<Record> expected, List<Row> actual) {
-    // TODO: match records by ID
-    int numRecords = Math.min(expected.size(), actual.size());
-    for (int i = 0; i < numRecords; i += 1) {
-      GenericsHelpers.assertEqualsSafe(struct, expected.get(i), actual.get(i));
+    Map<Long, Record> expectedById = new LinkedHashMap<>();
+    for (Record expectedRecord : expected) {
+      Long id = (Long) expectedRecord.getField("id");
+      assertThat(expectedById.put(id, expectedRecord))
+          .as("Expected record ID %s should be unique", id)
+          .isNull();
+    }
+
+    for (Row actualRecord : actual) {
+      Long id = actualRecord.getAs("id");
+      Record expectedRecord = expectedById.remove(id);
+      assertThat(expectedRecord).as("No expected record found for ID %s", 
id).isNotNull();

Review Comment:
   Addressed



-- 
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