Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_statements(self):

@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()
Expand All @@ -89,8 +89,8 @@ def __process_identifier(self, identifier):
# 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)
Copy link
Member Author

@john-bodley john-bodley Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note there's no need to call self.__get_full_name(identifier) again as the return value is captured by the table_name variable.

return

# store aliases
Expand Down
5 changes: 5 additions & 0 deletions tests/sql_parse_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def test_simple_select(self):
{'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))
Expand Down