Hisoka-X commented on code in PR #9103:
URL: https://github.com/apache/seatunnel/pull/9103#discussion_r2039290111
##########
seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java:
##########
@@ -262,21 +262,41 @@ private List<List<String>> decodeJSON(String data) {
List<String> result = jsonReadContext.read(path);
results.add(result);
}
- for (int i = 1; i < results.size(); i++) {
- List<?> result0 = results.get(0);
- List<?> result = results.get(i);
- if (result0.size() != result.size()) {
- throw new HttpConnectorException(
- HttpConnectorErrorCode.FIELD_DATA_IS_INCONSISTENT,
- String.format(
- "[%s](%d) and [%s](%d) the number of parsing
records is inconsistent.",
- jsonPaths[0].getPath(),
- result0.size(),
- jsonPaths[i].getPath(),
- result.size()));
+ if (httpParameter.isJsonFiledMissedReturnNull()) {
+ int maxLength = 0;
+ for (List<?> result : results) {
+ maxLength = Math.max(maxLength, result.size());
+ }
+ for (int i = 0; i < results.size(); i++) {
+ List<String> result = results.get(i);
+ if (result.size() < maxLength) {
+ log.warn(
+ "Field [{}] with size ({}) is less than max size
({}), will be padded with null values. "
+ + "This may happen when JSON paths return
different numbers of elements.",
+ jsonPaths[i].getPath(),
+ result.size(),
+ maxLength);
+ for (int j = result.size(); j < maxLength; j++) {
+ result.add(null);
+ }
+ }
+ }
+ } else {
Review Comment:
This solution will cause the data to be out of order. For example:
```json
[{
"key1":"value11",
"key2":"value22"
},
{
"key2":"value33"
"key3":"value44"
},
{
"key1":"value55"
"key3":"value66"
}
]
```
Json Fields:
```hocon
json_field = {
key1 = "$[*].key1"
key2 = "$[*].key2"
}
```
The expected results should be:
| key1| key2|
| --- | --- |
| value11 | value22 |
| null | value33 |
| value55 | null |
But current logic of results is:
| key1| key2|
| --- | --- |
| value11 | value22 |
| value55 | value33 |
The current implementation just wants to add null at the end, but does not
accurately locate which data is null.
--
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]