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


##########
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:
+        Assert.assertEquals("boolean value should be equal", expected, actual);
+        break;
+      case INTEGER:
+        Assert.assertEquals("int value should be equal", expected, actual);
+        break;
+      case LONG:
+        Assert.assertEquals("long value should be equal", expected, actual);
+        break;
+      case FLOAT:
+        Assert.assertEquals("float value should be equal", expected, actual);
+        break;
+      case DOUBLE:
+        Assert.assertEquals("double value should be equal", expected, actual);
+        break;
+      case STRING:
+        Assertions.assertThat(expected)
+            .as("Should expect a CharSequence")
+            .isInstanceOf(CharSequence.class);
+        Assert.assertEquals("string should be equal", 
String.valueOf(expected), actual.toString());
+        break;
+      case DATE:
+        Assertions.assertThat(expected).as("Should expect a 
Date").isInstanceOf(LocalDate.class);

Review Comment:
   I'm not sure about that. If it is needed, it would be good to add it.
   



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