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_r199312645
 
 

 ##########
 File path: superset/db_engine_specs.py
 ##########
 @@ -110,32 +110,26 @@ def apply_limit_to_sql(cls, sql, limit, database):
             )
             return database.compile_sqla_query(qry)
         elif LimitMethod.FORCE_LIMIT:
-            sql_without_limit = cls.get_query_without_limit(sql)
-            return '{sql_without_limit} LIMIT {limit}'.format(**locals())
+            parsed_query = sql_parse.SupersetQuery(sql)
+            sql_before_limit, sql_after_limit = (
+                cls.get_substrings_before_and_after_limit(sql)
+            )
+            sql = '{sql_before_limit} LIMIT {limit} 
{sql_after_limit}'.format(**locals())
+            re.sub('\s+', ' ', sql).strip()
 
 Review comment:
   I don't think you want to be stripping additional whitespace in free-from 
SQL as the author may have included this on purpose, i.e., 
   ```
   SELECT * FROM my_table WHERE paragraph LIKE '%.  The%'
   ```

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