superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnbod...@apache.org
Subject [incubator-superset] branch master updated: [sqlparse] Fixing table name extraction for ill-defined query (#7029)
Date Fri, 15 Mar 2019 16:19:38 GMT
This is an automated email from the ASF dual-hosted git repository.

johnbodley 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 07c340c  [sqlparse] Fixing table name extraction for ill-defined query (#7029)
07c340c is described below

commit 07c340cf8203f13222f16efad1e55e202deb1865
Author: John Bodley <4567245+john-bodley@users.noreply.github.com>
AuthorDate: Fri Mar 15 09:19:30 2019 -0700

    [sqlparse] Fixing table name extraction for ill-defined query (#7029)
---
 superset/sql_parse.py    | 6 +++---
 tests/sql_parse_tests.py | 5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index b653c88..8076f09 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -76,7 +76,7 @@ class ParsedQuery(object):
 
     @staticmethod
     def __get_full_name(identifier):
-        if len(identifier.tokens) > 1 and identifier.tokens[1].value == '.':
+        if len(identifier.tokens) > 2 and identifier.tokens[1].value == '.':
             return '{}.{}'.format(identifier.tokens[0].value,
                                   identifier.tokens[2].value)
         return identifier.get_real_name()
@@ -89,8 +89,8 @@ class ParsedQuery(object):
         # exclude subselects
         if '(' not in str(identifier):
             table_name = self.__get_full_name(identifier)
-            if not table_name.startswith(CTE_PREFIX):
-                self._table_names.add(self.__get_full_name(identifier))
+            if table_name and not table_name.startswith(CTE_PREFIX):
+                self._table_names.add(table_name)
             return
 
         # store aliases
diff --git a/tests/sql_parse_tests.py b/tests/sql_parse_tests.py
index e821fce..5695939 100644
--- a/tests/sql_parse_tests.py
+++ b/tests/sql_parse_tests.py
@@ -47,6 +47,11 @@ class SupersetTestCase(unittest.TestCase):
             {'schemaname.tbname'},
             self.extract_tables('SELECT * FROM schemaname.tbname'))
 
+        # Ill-defined schema/table.
+        self.assertEquals(
+            set(),
+            self.extract_tables('SELECT * FROM schemaname.'))
+
         # quotes
         query = 'SELECT field1, field2 FROM tb_name'
         self.assertEquals({'tb_name'}, self.extract_tables(query))


Mime
View raw message