superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [incubator-superset] branch master updated: Trim query before parsing (#6703)
Date Thu, 17 Jan 2019 17:16:42 GMT
This is an automated email from the ASF dual-hosted git repository.

beto 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 99d6dc0  Trim query before parsing (#6703)
99d6dc0 is described below

commit 99d6dc07d6910ae5c5fe0d5f98e993bc960dff73
Author: Beto Dealmeida <roberto@dealmeida.net>
AuthorDate: Thu Jan 17 09:16:35 2019 -0800

    Trim query before parsing (#6703)
    
    * Ignore empty lines
    
    * Fix unit tests
    
    * Use stripped
    
    * Fix another unit test
---
 superset/sql_parse.py         |  2 +-
 tests/db_engine_specs_test.py | 14 +++++---------
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index 2422c1c..241917a 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -34,7 +34,7 @@ class ParsedQuery(object):
         self._limit = None
 
         logging.info('Parsing with sqlparse statement {}'.format(self.sql))
-        self._parsed = sqlparse.parse(self.sql)
+        self._parsed = sqlparse.parse(self.stripped())
         for statement in self._parsed:
             self.__extract_from_token(statement)
             self._limit = self._extract_limit_from_query(statement)
diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py
index c04810d..c2f1713b 100644
--- a/tests/db_engine_specs_test.py
+++ b/tests/db_engine_specs_test.py
@@ -196,8 +196,7 @@ class DbEngineSpecsTestCase(SupersetTestCase):
             FROM
             table
             LIMIT 99990""",
-            """
-            SELECT
+            """SELECT
                 'LIMIT 777' AS a
                 , b
             FROM
@@ -214,13 +213,12 @@ class DbEngineSpecsTestCase(SupersetTestCase):
                 FROM
                 table
                 LIMIT         99990            ;""",
-            """
-                SELECT
+            """SELECT
                     'LIMIT 777' AS a
                     , b
                 FROM
                 table
-                LIMIT         1000            ;""",
+                LIMIT         1000""",
         )
 
     def test_get_datatype(self):
@@ -238,8 +236,7 @@ class DbEngineSpecsTestCase(SupersetTestCase):
                 FROM
                 table
                 LIMIT 99990, 999999""",
-            """
-                SELECT
+            """SELECT
                     'LIMIT 777' AS a
                     , b
                 FROM
@@ -257,8 +254,7 @@ class DbEngineSpecsTestCase(SupersetTestCase):
                 table
                 LIMIT 99990
                 OFFSET 999999""",
-            """
-                SELECT
+            """SELECT
                     'LIMIT 777' AS a
                     , b
                 FROM


Mime
View raw message