john-bodley commented on a change in pull request #5295: [sqllab] Fix sqllab 
limit regex issue with sqlparse
URL: 
https://github.com/apache/incubator-superset/pull/5295#discussion_r200439111
 
 

 ##########
 File path: superset/sql_parse.py
 ##########
 @@ -128,3 +134,43 @@ def __extract_from_token(self, token):
                 for token in item.tokens:
                     if self.__is_identifier(token):
                         self.__process_identifier(token)
+
+    def _get_limit_from_token(self, token):
+        if token.ttype == sqlparse.tokens.Literal.Number.Integer:
+            return int(token.value)
+        elif token.is_group:
+            return int(token.get_token_at_offset(1).value)
+
+    def _extract_limit_from_outermost_layer(self, statement):
+        limit_token = None
+        for pos, item in enumerate(statement.tokens):
+            if item.ttype in Keyword and item.value.lower() == 'limit':
+                limit_token = statement.tokens[pos + 2]
+                break
+        if not limit_token:
+            return limit_token
+        return self._get_limit_from_token(limit_token)
 
 Review comment:
   Also the term `outermost` may be misleading. You can argue that iterating 
backwards would find the outermost `LIMIT` condition.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to