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 2020/04/24 11:29:45 UTC
[GitHub] [incubator-superset] villebro commented on a change in pull request #9644: [mssql] Fix, apply limit and set alias for functions
villebro commented on a change in pull request #9644:
URL: https://github.com/apache/incubator-superset/pull/9644#discussion_r414502775
##########
File path: superset/sql_parse.py
##########
@@ -247,3 +254,34 @@ def set_or_update_query_limit(self, new_limit: int) -> str:
for i in statement.tokens:
str_res += str(i.value)
return str_res
+
+ def set_alias(self) -> str:
+ """
+ Returns a new query string where all functions have alias.
+ This is particularly necessary for MSSQL engines.
+
+ :return: String with new aliased SQL query
+ """
+ new_sql = ""
+ for token in self._parsed[0].tokens:
+ # Identifier list (list of columns)
+ if isinstance(token, IdentifierList) and token.ttype is None:
+ for i, identifier in enumerate(token.get_identifiers()):
+ # Functions are anonymous on MSSQL
+ if isinstance(identifier, Function) and not identifier.has_alias():
+ identifier.value = (
+ f"{identifier.value} as {identifier.get_real_name()}"
+ )
+ new_sql += str(identifier.value)
+ # If not last identifier
+ if i != len(list(token.get_identifiers())) - 1:
+ new_sql += ", "
+ # Just a lonely function?
+ elif isinstance(token, Function) and token.ttype is None:
+ if not token.has_alias():
+ token.value = f"{token.value} as {token.get_real_name()}"
Review comment:
nit: uppercase `AS`
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org