njnu-seafish commented on code in PR #17702:
URL:
https://github.com/apache/dolphinscheduler/pull/17702#discussion_r2575532541
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java:
##########
@@ -248,11 +250,38 @@ private String resultProcess(ResultSet resultSet) throws
Exception {
int num = md.getColumnCount();
while (resultSet.next()) {
- ObjectNode mapOfColValues = JSONUtils.createObjectNode();
+ ObjectNode rowAsJson = JSONUtils.createObjectNode();
+ Set<String> usedLabels = new HashSet<>();
+
for (int i = 1; i <= num; i++) {
- mapOfColValues.set(md.getColumnLabel(i),
JSONUtils.toJsonNode(resultSet.getObject(i)));
+ // Get the column label (alias) from metadata; fall back
to a generic name if null or empty
+ String baseLabel = md.getColumnLabel(i);
+ if (baseLabel == null || baseLabel.isEmpty()) {
+ baseLabel = "col_" + i;
+ }
+
+ // Generate a unique field key for the JSON object:
+ // If the base label is already used in this row, append a
numeric suffix (e.g., name_2, name_3)
+ String finalLabel = baseLabel;
+ int suffix = 2; // Start numbering duplicates from _2 to
keep the first occurrence clean
+
+ while (!usedLabels.add(finalLabel)) {
+ finalLabel = baseLabel + "_" + suffix++;
+ }
+
+ // Read the column value and convert it to a JSON node
Review Comment:
>
ok,done
--
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]