[Fix][Transform-V2][JsonPath] Fix date/time conversion error when mul…#10390
[Fix][Transform-V2][JsonPath] Fix date/time conversion error when mul…#10390yht0827 wants to merge 37 commits intoapache:devfrom
Conversation
…tiple date columns exist
|
Please enable CI following the instructions. |
dybyte
left a comment
There was a problem hiding this comment.
I think we should add null checks in JsonRowConverters#convertToLocalDate and JsonRowConverters#convertToLocalDateTime.
Also, could you add test cases for these two methods in JsonRowDataSerDeSchemaTest?
|
There is currently a problem with CI, and you need to enable it. |
|
Thanks for the review! I’ll add null checks to |
Issue 1: Test coverage is not comprehensive enoughLocation: Related Context:
Problem Description: The newly added test cases cover the scenarios of "multiple date columns with different formats" and "containing null values", but are missing the following scenarios:
Potential Risks:
Impact Scope:
Severity: MINOR Improvement Suggestions: @Test
public void testSingleDateColumn() {
// Verify that the behavior of a single date column remains consistent with the modifications
Map<String, Object> configMap = new HashMap<>();
configMap.put(
JsonPathTransformConfig.COLUMNS.key(),
Arrays.asList(
ImmutableMap.of(
JsonPathTransformConfig.SRC_FIELD.key(), "data",
JsonPathTransformConfig.PATH.key(), "$.birth",
JsonPathTransformConfig.DEST_FIELD.key(), "birth_date",
JsonPathTransformConfig.DEST_TYPE.key(), "date")));
// ... test logic
}
@Test
public void testMultipleDateColumnsWithSameFormat() {
// Verify that multiple date columns with the same format can share cache
Map<String, Object> configMap = new HashMap<>();
configMap.put(
JsonPathTransformConfig.COLUMNS.key(),
Arrays.asList(
ImmutableMap.of(..., "birth", "birth_date", "date"),
ImmutableMap.of(..., "hired", "hire_date", "date")));
String jsonData = "{\"birth\": \"2024-01-15\", \"hired\": \"2024-02-20\"}";
// ... verify both fields are correctly parsed
}
@Test
public void testMixedTypeColumns() {
// Verify mixed configuration of date columns with string and integer columns
Map<String, Object> configMap = new HashMap<>();
configMap.put(
JsonPathTransformConfig.COLUMNS.key(),
Arrays.asList(
ImmutableMap.of(..., "date_field", "date"),
ImmutableMap.of(..., "string_field", "string"),
ImmutableMap.of(..., "int_field", "int")));
// ... verify all types are correctly converted
}Rationale:
Issue 4: Insufficient encapsulability of fieldFormatterMapLocation: Related Context:
Problem Description:
Potential Risks:
Impact Scope:
Severity: MINOR Improvement Suggestions: // Current (line 80)
public Map<String, DateTimeFormatter> fieldFormatterMap = new HashMap<>();
// Suggested change to
private Map<String, DateTimeFormatter> fieldFormatterMap = new HashMap<>();
// If tests need access, add package-level visible access methods
Map<String, DateTimeFormatter> getFieldFormatterMap() {
return fieldFormatterMap;
}
// Or provide controlled access methods
public DateTimeFormatter getCachedFormatter(String fieldName) {
return fieldFormatterMap.get(fieldName);
}Rationale:
Note: This issue is outside the scope of this PR and is an existing problem in the codebase. However, since it was discovered during review, it should be recorded for future improvement. |
…tiple date columns exist
…tiple date columns exist
…n' into fix/jsonpath-destfield-conversion
|
@dybyte @DanielCarter-stack Thanks for the detailed reviews! I've added the following test cases to cover the requested scenarios: JsonPathTransformTest
JsonRowDataSerDeSchemaTest
@DanielCarter-stack I'm also interested in working on issue 4. Will create a follow-up PR after this one is merged. Please review when you have time. |
...eatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/JsonToRowConverters.java
Show resolved
Hide resolved
...eatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/JsonToRowConverters.java
Show resolved
Hide resolved
...l-format-json/src/test/java/org/apache/seatunnel/format/json/JsonRowDataSerDeSchemaTest.java
Show resolved
Hide resolved
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/JsonPathTransformTest.java
Outdated
Show resolved
Hide resolved
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/JsonPathTransformTest.java
Outdated
Show resolved
Hide resolved
...eatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/JsonToRowConverters.java
Outdated
Show resolved
Hide resolved
...eatunnel-format-json/src/main/java/org/apache/seatunnel/format/json/JsonToRowConverters.java
Outdated
Show resolved
Hide resolved
...l-format-json/src/test/java/org/apache/seatunnel/format/json/JsonRowDataSerDeSchemaTest.java
Show resolved
Hide resolved
|
@yht0827 Could you please retry the CI without adding any additional commits? |
I’ve retriggered the CI without adding any new commits, but it failed again. |
…n' into fix/jsonpath-destfield-conversion
|
@zhangshenghang @DanielCarter-stack Could you please take another look at this PR? The JsonPath multi date/datetime column issue has been fixed, and the requested null checks and tests have all been applied. If everything looks good, I’d really appreciate your approval. |
Fixes: #10333
Purpose of this pull request
When using JsonPath transform with multiple date/timestamp columns, the converter received
nullas the field name, causing incorrect date format resolution.Fixed by passing
columnConfig.getDestField()to the converter, ensuring each column resolves its own date format correctly.Does this PR introduce any user-facing change?
Yes. Previously, multiple date/timestamp columns in JsonPath transform could fail or produce incorrect results due to missing field name context. Now each column correctly applies its configured date/time format.
How was this patch tested?
Check list
New License Guide
incompatible-changes.mdto describe the incompatibility caused by this PR.