You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/05/22 22:58:56 UTC

[GitHub] john-bodley commented on a change in pull request #5023: [sqllab] force limit queries only when there is no existing limit

john-bodley commented on a change in pull request #5023: [sqllab] force limit queries only when there is no existing limit
URL: https://github.com/apache/incubator-superset/pull/5023#discussion_r190077930
 
 

 ##########
 File path: superset/utils.py
 ##########
 @@ -841,3 +842,31 @@ def ensure_path_exists(path):
     except OSError as exc:
         if not (os.path.isdir(path) and exc.errno == errno.EEXIST):
             raise
+
+
+def get_query_without_limit(sql):
+    return re.sub(r"""
+                (?ix)        # case insensitive, verbose
+                \s+          # whitespace
+                LIMIT\s+\d+  # LIMIT $ROWS
+                ;?           # optional semi-colon
+                (\s|;)*$     # remove trailing spaces tabs or semicolons
+                """, '', sql)
+
+
+def get_limit_from_sql(sql):
+    # returns the limit of the quest or None if it has none
+    sql_without_limit = get_query_without_limit(sql)
+    if sql_without_limit != sql:
+        limit_clause = sql.partition(sql_without_limit)[2]
+        limit_match = re.search('limit\s(\d+)', limit_clause, re.IGNORECASE)
+        if limit_match:
+            specified_limit = limit_match.group(1)
+            try:
+                specified_limit = int(specified_limit) if specified_limit else None
 
 Review comment:
   Not that it's applicable because the try/except is unnecessary but there's no need to do the if/else logic as the `specified_limit` is assigned to `None` on line 870.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org