You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/04/24 21:09:35 UTC

[GitHub] [incubator-superset] john-bodley commented on a change in pull request #7374: [fix] Fixing SQL parsing issue

john-bodley commented on a change in pull request #7374: [fix] Fixing SQL parsing issue
URL: https://github.com/apache/incubator-superset/pull/7374#discussion_r278319100
 
 

 ##########
 File path: superset/sql_parse.py
 ##########
 @@ -75,32 +75,32 @@ def get_statements(self):
         return statements
 
     @staticmethod
-    def __get_full_name(identifier):
-        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()
+    def __get_full_name(tlist: TokenList):
+        if len(tlist.tokens) > 2 and tlist.tokens[1].value == '.':
+            return '{}.{}'.format(tlist.tokens[0].value,
+                                  tlist.tokens[2].value)
+        return tlist.get_real_name()
 
     @staticmethod
-    def __is_identifier(token):
+    def __is_identifier(token: Token):
         return isinstance(token, (IdentifierList, Identifier))
 
-    def __process_identifier(self, identifier):
+    def __process_tokenlist(self, tlist: TokenList):
         # exclude subselects
-        if '(' not in str(identifier):
-            table_name = self.__get_full_name(identifier)
+        if '(' not in str(tlist):
+            table_name = self.__get_full_name(tlist)
             if table_name and not table_name.startswith(CTE_PREFIX):
                 self._table_names.add(table_name)
             return
 
         # store aliases
-        if hasattr(identifier, 'get_alias'):
-            self._alias_names.add(identifier.get_alias())
-        if hasattr(identifier, 'tokens'):
-            # some aliases are not parsed properly
-            if identifier.tokens[0].ttype == Name:
-                self._alias_names.add(identifier.tokens[0].value)
-        self.__extract_from_token(identifier)
+        if tlist.has_alias():
 
 Review comment:
   By construction there's no need to check whether the `get_alias` attribute exists as [this](https://github.com/andialbrecht/sqlparse/blob/master/sqlparse/sql.py#L342) method is defined in the `TokenList` class. Note an alias can be `None` and thus if there is no alias we shouldn't add it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org