ruanwenjun commented on a change in pull request #5324:
URL: https://github.com/apache/dolphinscheduler/pull/5324#discussion_r616589494



##########
File path: 
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
##########
@@ -304,34 +304,36 @@ public String setNonQuerySqlReturn(String updateResult, 
List<Property> propertie
      */
     private String resultProcess(ResultSet resultSet) throws Exception {
         ArrayNode resultJSONArray = JSONUtils.createArrayNode();
-        ResultSetMetaData md = resultSet.getMetaData();
-        int num = md.getColumnCount();
-
-        int rowCount = 0;
-
-        while (rowCount < LIMIT && resultSet.next()) {
-            ObjectNode mapOfColValues = JSONUtils.createObjectNode();
-            for (int i = 1; i <= num; i++) {
-                mapOfColValues.set(md.getColumnLabel(i), 
JSONUtils.toJsonNode(resultSet.getObject(i)));
+        if (resultSet != null) {
+            ResultSetMetaData md = resultSet.getMetaData();
+            int num = md.getColumnCount();
+
+            int rowCount = 0;
+
+            while (rowCount < LIMIT && resultSet.next()) {
+                ObjectNode mapOfColValues = JSONUtils.createObjectNode();
+                for (int i = 1; i <= num; i++) {
+                    mapOfColValues.set(md.getColumnLabel(i), 
JSONUtils.toJsonNode(resultSet.getObject(i)));
+                }
+                resultJSONArray.add(mapOfColValues);
+                rowCount++;
             }
-            resultJSONArray.add(mapOfColValues);
-            rowCount++;
-        }
-        String result = JSONUtils.toJsonString(resultJSONArray);
-        logger.debug("execute sql result : {}", result);
 
-        int displayRows = sqlParameters.getDisplayRows() > 0 ? 
sqlParameters.getDisplayRows() : Constants.DEFAULT_DISPLAY_ROWS;
-        displayRows = Math.min(displayRows, resultJSONArray.size());
-        logger.info("display sql result {} rows as follows:", displayRows);
-        for (int i = 0; i < displayRows; i++) {
-            String row = JSONUtils.toJsonString(resultJSONArray.get(i));
-            logger.info("row {} : {}", i + 1, row);
+            int displayRows = sqlParameters.getDisplayRows() > 0 ? 
sqlParameters.getDisplayRows() : Constants.DEFAULT_DISPLAY_ROWS;
+            displayRows = Math.min(displayRows, resultJSONArray.size());
+            logger.info("display sql result {} rows as follows:", displayRows);
+            for (int i = 0; i < displayRows; i++) {
+                String row = JSONUtils.toJsonString(resultJSONArray.get(i));
+                logger.info("row {} : {}", i + 1, row);
+            }
         }
 
         if (sqlParameters.getSendEmail() == null || 
sqlParameters.getSendEmail()) {
             sendAttachment(sqlParameters.getGroupId(), 
StringUtils.isNotEmpty(sqlParameters.getTitle()) ? sqlParameters.getTitle() : 
taskExecutionContext.getTaskName() + " query result sets",
                     JSONUtils.toJsonString(resultJSONArray));
         }
+        String result = JSONUtils.toJsonString(resultJSONArray);

Review comment:
       Good suggestion, modification has been completed.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to