etr2460 commented on a change in pull request #7641: [SQL Lab] Clarify SQL Lab 
query and display limits
URL: 
https://github.com/apache/incubator-superset/pull/7641#discussion_r291776703
 
 

 ##########
 File path: superset/views/utils.py
 ##########
 @@ -184,3 +185,23 @@ def get_datasource_info(datasource_id, datasource_type, 
form_data):
             'The datasource associated with this chart no longer exists')
     datasource_id = int(datasource_id)
     return datasource_id, datasource_type
+
+
+def apply_display_max_row_limit(sql_results):
+    """
+    Given a `sql_results` nested structure, applies a limit to the number of 
rows
+
+    `sql_results` here is the nested structure coming out of 
sql_lab.get_sql_results, it
+    contains metadata about the query, as well as the data set returned by the 
query.
+    This method limits the number of rows adds a `displayLimitReached: True` 
flag to the
+    metadata.
+    """
+    display_limit = app.config.get('DISPLAY_MAX_ROW')
+    if (
+        display_limit and
+        sql_results['status'] == QueryStatus.SUCCESS and
+        display_limit < sql_results['query']['rows']
+    ):
+        sql_results['data'] = sql_results['data'][:display_limit]
+        sql_results['displayLimitReached'] = True
+    return sql_results
 
 Review comment:
   I'm returning it so I can call the function inline. And types added!

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to