stevenzwu commented on code in PR #6222:
URL: https://github.com/apache/iceberg/pull/6222#discussion_r1066110588


##########
flink/v1.16/flink/src/test/java/org/apache/iceberg/flink/TestHelpers.java:
##########
@@ -295,6 +299,161 @@ private static void assertEquals(
     }
   }
 
+  public static void assertEqualsSafe(
+      Schema schema, List<GenericData.Record> recs, List<Row> rows) {
+    Streams.forEachPair(
+        recs.stream(), rows.stream(), (rec, row) -> assertEqualsSafe(schema, 
rec, row));
+  }
+
+  public static void assertEqualsSafe(Schema schema, GenericData.Record rec, 
Row row) {
+    List<Types.NestedField> fields = schema.asStruct().fields();
+    RowType rowType = FlinkSchemaUtil.convert(schema);
+    for (int i = 0; i < fields.size(); i += 1) {
+      Type fieldType = fields.get(i).type();
+      Object expectedValue = rec.get(i);
+      Object actualValue = row.getField(i);
+      LogicalType logicalType = rowType.getTypeAt(i);
+      assertAvroEquals(fieldType, logicalType, expectedValue, actualValue);
+    }
+  }
+
+  private static void assertEqualsSafe(Types.StructType struct, 
GenericData.Record rec, Row row) {
+    List<Types.NestedField> fields = struct.fields();
+    for (int i = 0; i < fields.size(); i += 1) {
+      Type fieldType = fields.get(i).type();
+      Object expectedValue = rec.get(i);
+      Object actualValue = row.getField(i);
+      assertAvroEquals(fieldType, null, expectedValue, actualValue);
+    }
+  }
+
+  private static void assertAvroEquals(
+      Type type, LogicalType logicalType, Object expected, Object actual) {
+
+    if (expected == null && actual == null) {
+      return;
+    }
+
+    Assert.assertTrue(
+        "expected and actual should be both null or not null", expected != 
null && actual != null);
+
+    switch (type.typeId()) {
+      case BOOLEAN:

Review Comment:
   BOOLEAN to DOUBLE can be collapsed to avoid repetition. The error msg can 
include the type name. Also we should check the type of the expected and actual 
values. E.g., for INTEGER type, if both expected and actual are string values. 
the test will pass incorrectly.



##########
flink/v1.16/flink/src/test/java/org/apache/iceberg/flink/TestHelpers.java:
##########
@@ -295,6 +299,161 @@ private static void assertEquals(
     }
   }
 
+  public static void assertEqualsSafe(
+      Schema schema, List<GenericData.Record> recs, List<Row> rows) {
+    Streams.forEachPair(
+        recs.stream(), rows.stream(), (rec, row) -> assertEqualsSafe(schema, 
rec, row));
+  }
+
+  public static void assertEqualsSafe(Schema schema, GenericData.Record rec, 
Row row) {
+    List<Types.NestedField> fields = schema.asStruct().fields();
+    RowType rowType = FlinkSchemaUtil.convert(schema);
+    for (int i = 0; i < fields.size(); i += 1) {
+      Type fieldType = fields.get(i).type();
+      Object expectedValue = rec.get(i);
+      Object actualValue = row.getField(i);
+      LogicalType logicalType = rowType.getTypeAt(i);
+      assertAvroEquals(fieldType, logicalType, expectedValue, actualValue);
+    }
+  }
+
+  private static void assertEqualsSafe(Types.StructType struct, 
GenericData.Record rec, Row row) {
+    List<Types.NestedField> fields = struct.fields();
+    for (int i = 0; i < fields.size(); i += 1) {
+      Type fieldType = fields.get(i).type();
+      Object expectedValue = rec.get(i);
+      Object actualValue = row.getField(i);
+      assertAvroEquals(fieldType, null, expectedValue, actualValue);
+    }
+  }
+
+  private static void assertAvroEquals(
+      Type type, LogicalType logicalType, Object expected, Object actual) {
+
+    if (expected == null && actual == null) {
+      return;
+    }
+
+    Assert.assertTrue(
+        "expected and actual should be both null or not null", expected != 
null && actual != null);
+
+    switch (type.typeId()) {
+      case BOOLEAN:

Review Comment:
   BOOLEAN to DOUBLE can be collapsed to avoid repetition. The error msg can 
include the type name. 
   
   Also we should check the type of the expected and actual values. E.g., for 
INTEGER type, if both expected and actual are string values. the test will pass 
incorrectly.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to