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

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 72d1011  [sqllab] Fix limit parsing bug when using limit-offset comma 
notation (#7912)
72d1011 is described below

commit 72d1011023cc441d85afe2d198bac25b21cff8cd
Author: Ville Brofeldt <[email protected]>
AuthorDate: Wed Jul 24 08:18:39 2019 +0300

    [sqllab] Fix limit parsing bug when using limit-offset comma notation 
(#7912)
    
    * Fix limit parsing bug when using limit-offset comma notation
    
    * Use native sqlparse semantics to find limit
    
    * black
---
 superset/sql_parse.py         | 5 ++++-
 tests/db_engine_specs_test.py | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index f52c80f..d68ac5e 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -182,7 +182,10 @@ class ParsedQuery(object):
             _, token = statement.token_next(idx=idx)
             if token:
                 if isinstance(token, IdentifierList):
-                    _, token = token.token_next(idx=-1)
+                    # In case of "LIMIT <offset>, <limit>", find comma and 
extract
+                    # first succeeding non-whitespace token
+                    idx, _ = 
token.token_next_by(m=(sqlparse.tokens.Punctuation, ","))
+                    _, token = token.token_next(idx=idx)
                 if token and token.ttype == 
sqlparse.tokens.Literal.Number.Integer:
                     return int(token.value)
 
diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py
index 733b9be..c9c398f 100644
--- a/tests/db_engine_specs_test.py
+++ b/tests/db_engine_specs_test.py
@@ -175,12 +175,12 @@ class DbEngineSpecsTestCase(SupersetTestCase):
         q2 = "select * from (select * from my_subquery limit 10) where col=1 
limit 20"
         q3 = "select * from (select * from my_subquery limit 10);"
         q4 = "select * from (select * from my_subquery limit 10) where col=1 
limit 20;"
-        q5 = "select * from mytable limit 10, 20"
+        q5 = "select * from mytable limit 20, 10"
         q6 = "select * from mytable limit 10 offset 20"
         q7 = "select * from mytable limit"
         q8 = "select * from mytable limit 10.0"
         q9 = "select * from mytable limit x"
-        q10 = "select * from mytable limit x, 20"
+        q10 = "select * from mytable limit 20, x"
         q11 = "select * from mytable limit x offset 20"
 
         self.assertEqual(engine_spec_class.get_limit_from_sql(q0), None)

Reply via email to