You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by jo...@apache.org on 2020/04/27 02:23:36 UTC

[incubator-dolphinscheduler] branch dev updated: Add query result set limit. (#2459)

This is an automated email from the ASF dual-hosted git repository.

journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new c50ad12  Add query result set limit. (#2459)
c50ad12 is described below

commit c50ad1240c4789403e9518c855c0217fc9030b5b
Author: t1mon <17...@qq.com>
AuthorDate: Mon Apr 27 10:23:29 2020 +0800

    Add query result set limit. (#2459)
    
    * Optimize PropertyUtils instantiation.
    
    * Fix info error.
    
    * Add query result set limit.
    
    * fix code smell
    
    Co-authored-by: dailidong <da...@gmail.com>
    Co-authored-by: qiaozhanwei <qi...@outlook.com>
---
 .../dolphinscheduler/server/worker/task/sql/SqlTask.java     | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
index 22fa91d..84e4e54 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
@@ -16,7 +16,6 @@
  */
 package org.apache.dolphinscheduler.server.worker.task.sql;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
@@ -24,7 +23,6 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.dolphinscheduler.alert.utils.MailUtils;
 import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.*;
-import org.apache.dolphinscheduler.common.enums.AuthorizationType;
 import org.apache.dolphinscheduler.common.enums.DbType;
 import org.apache.dolphinscheduler.common.enums.ShowType;
 import org.apache.dolphinscheduler.common.enums.TaskTimeoutStrategy;
@@ -37,7 +35,6 @@ import org.apache.dolphinscheduler.common.utils.*;
 import org.apache.dolphinscheduler.dao.AlertDao;
 import org.apache.dolphinscheduler.dao.datasource.BaseDataSource;
 import org.apache.dolphinscheduler.dao.datasource.DataSourceFactory;
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
 import org.apache.dolphinscheduler.dao.entity.User;
 import org.apache.dolphinscheduler.server.entity.SQLTaskExecutionContext;
 import org.apache.dolphinscheduler.server.entity.TaskExecutionContext;
@@ -78,6 +75,10 @@ public class SqlTask extends AbstractTask {
      */
     private TaskExecutionContext taskExecutionContext;
 
+    /**
+     * default query sql limit
+     */
+    private static final int LIMIT = 10000;
 
     public SqlTask(TaskExecutionContext taskExecutionContext, Logger logger) {
         super(taskExecutionContext, logger);
@@ -257,12 +258,15 @@ public class SqlTask extends AbstractTask {
         ResultSetMetaData md = resultSet.getMetaData();
         int num = md.getColumnCount();
 
-        while (resultSet.next()) {
+        int rowCount = 0;
+
+        while (rowCount < LIMIT && resultSet.next()) {
             JSONObject mapOfColValues = new JSONObject(true);
             for (int i = 1; i <= num; i++) {
                 mapOfColValues.put(md.getColumnName(i), resultSet.getObject(i));
             }
             resultJSONArray.add(mapOfColValues);
+            rowCount++;
         }
         logger.debug("execute sql : {}", JSONObject.toJSONString(resultJSONArray, SerializerFeature.WriteMapNullValue));