Skip to content

Commit

Permalink
refactor(sql): optimize sql query parser (apache#9673)
Browse files Browse the repository at this point in the history
* optimize sql query parser

* update extract from token

* update doc string

* pylint doc string
  • Loading branch information
lilykuang authored and auxten committed Nov 20, 2020
1 parent 2facb98 commit 65b8c24
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions superset/sql_parse.py
Expand Up @@ -208,7 +208,13 @@ def _extract_from_token( # pylint: disable=too-many-branches
self, token: Token
) -> None:
"""
Populate self._tables from token
<Identifier> store a list of subtokens and <IdentifierList> store lists of
subtoken list.
It extracts <IdentifierList> and <Identifier> from :param token: and loops
through all subtokens recursively. It finds table_name_preceding_token and
passes <IdentifierList> and <Identifier> to self._process_tokenlist to populate
self._tables.
:param token: instance of Token or child class, e.g. TokenList, to be processed
"""
Expand Down Expand Up @@ -240,9 +246,8 @@ def _extract_from_token( # pylint: disable=too-many-branches
if isinstance(token2, TokenList):
self._process_tokenlist(token2)
elif isinstance(item, IdentifierList):
for token2 in item.tokens:
if not self._is_identifier(token2):
self._extract_from_token(item)
if any(not self._is_identifier(token2) for token2 in item.tokens):
self._extract_from_token(item)

def set_or_update_query_limit(self, new_limit: int) -> str:
"""Returns the query with the specified limit.
Expand Down

0 comments on commit 65b8c24

Please sign in to comment.