dybyte commented on code in PR #10390:
URL: https://github.com/apache/seatunnel/pull/10390#discussion_r2737856440


##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/JsonToRowConverters.java:
##########
@@ -277,6 +282,11 @@ private LocalTime convertToLocalTime(JsonNode jsonNode) {
 
     private LocalDateTime convertToLocalDateTime(JsonNode jsonNode, String 
fieldName) {
         String datetimeStr = jsonNode.asText();
+
+        if (datetimeStr == null || datetimeStr.trim().isEmpty()) {
+            return null;
+        }
+

Review Comment:
   ditto



##########
seatunnel-formats/seatunnel-format-json/src/test/java/org/apache/seatunnel/format/json/JsonRowDataSerDeSchemaTest.java:
##########
@@ -713,4 +713,54 @@ public void testSerializationWithNumber() {
         String expected = "{\"id\":1,\"code\":\"1001015\",\"fe_result\":80}";
         assertEquals(new String(serialize), expected);
     }
+
+    @Test
+    public void testConvertToLocalDateWithEmptyString() throws IOException {
+        SeaTunnelRowType rowType =
+                new SeaTunnelRowType(
+                        new String[] {"date_field"},
+                        new SeaTunnelDataType<?>[] 
{LocalTimeType.LOCAL_DATE_TYPE});
+        JsonDeserializationSchema deserializationSchema =
+                new JsonDeserializationSchema(false, false, rowType);
+
+        // Test empty string
+        String emptyDateJson = "{\"date_field\":\"\"}";
+        SeaTunnelRow row = 
deserializationSchema.deserialize(emptyDateJson.getBytes());
+        assertNull(row.getField(0));
+
+        // Test whitespace only string
+        String whitespaceJson = "{\"date_field\":\"   \"}";
+        row = deserializationSchema.deserialize(whitespaceJson.getBytes());
+        assertNull(row.getField(0));
+
+        // Test normal date value still works
+        String normalDateJson = "{\"date_field\":\"2024-01-15\"}";
+        row = deserializationSchema.deserialize(normalDateJson.getBytes());
+        assertEquals(LocalDate.of(2024, 1, 15), row.getField(0));
+    }
+
+    @Test
+    public void testConvertToLocalDateTimeWithEmptyString() throws IOException 
{
+        SeaTunnelRowType rowType =
+                new SeaTunnelRowType(
+                        new String[] {"timestamp_field"},
+                        new SeaTunnelDataType<?>[] 
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+        JsonDeserializationSchema deserializationSchema =
+                new JsonDeserializationSchema(false, false, rowType);
+
+        // Test empty string
+        String emptyTimestampJson = "{\"timestamp_field\":\"\"}";
+        SeaTunnelRow row = 
deserializationSchema.deserialize(emptyTimestampJson.getBytes());
+        assertNull(row.getField(0));
+
+        // Test whitespace only string
+        String whitespaceJson = "{\"timestamp_field\":\"   \"}";
+        row = deserializationSchema.deserialize(whitespaceJson.getBytes());
+        assertNull(row.getField(0));
+
+        // Test normal timestamp value still works
+        String normalTimestampJson = "{\"timestamp_field\":\"2024-01-15 
10:30:00\"}";
+        row = 
deserializationSchema.deserialize(normalTimestampJson.getBytes());
+        assertEquals(LocalDateTime.of(2024, 1, 15, 10, 30, 0), 
row.getField(0));
+    }

Review Comment:
   Are these tests related to the current PR? I’m not entirely sure about the 
connection.



##########
seatunnel-formats/seatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/JsonToRowConverters.java:
##########
@@ -258,6 +258,11 @@ private float convertToFloat(JsonNode jsonNode) {
 
     private LocalDate convertToLocalDate(JsonNode jsonNode, String fieldName) {
         String dateStr = jsonNode.asText();
+
+        if (dateStr == null || dateStr.trim().isEmpty()) {
+            return null;
+        }
+

Review Comment:
   I think we should check `fieldName` for null rather than `dateStr`.
   If `fieldName` is null, we shouldn’t put this entry into `fieldFormatterMap`.



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

Reply via email to