This is an automated email from the ASF dual-hosted git repository.
villebro 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 f6cd3a9 refactor(sql): optimize sql query parser (#9673)
f6cd3a9 is described below
commit f6cd3a917a162425e3289f7215ba305602bfa021
Author: Lily Kuang <[email protected]>
AuthorDate: Tue Jun 9 23:15:48 2020 -0700
refactor(sql): optimize sql query parser (#9673)
* optimize sql query parser
* update extract from token
* update doc string
* pylint doc string
---
superset/sql_parse.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index 3e50386..d87db83 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -208,7 +208,13 @@ class ParsedQuery:
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
"""
@@ -240,9 +246,8 @@ class ParsedQuery:
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.