ocean-zhc commented on code in PR #9103:
URL: https://github.com/apache/seatunnel/pull/9103#discussion_r2040677308
##########
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:
Yes, it was indeed an issue and I didn't take into account the data
correspondence, now I fixed 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]