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 09:31:24 UTC

[GitHub] [incubator-superset] dpgaspar opened a new pull request #9644: [mssql] Fix, apply limit and set alias for functions

dpgaspar opened a new pull request #9644:
URL: https://github.com/apache/incubator-superset/pull/9644


   ### CATEGORY
   
   Choose one
   
   - [X] Bug Fix
   - [ ] Enhancement (new features, refinement)
   - [ ] Refactor
   - [X] Add tests
   - [ ] Build / Development Environment
   - [ ] Documentation
   
   ### SUMMARY
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TEST PLAN
   <!--- What steps should be taken to verify the changes -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [ ] Requires DB Migration.
   - [ ] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ### REVIEWERS
   


----------------------------------------------------------------
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


[GitHub] [incubator-superset] codecov-io commented on pull request #9644: [mssql] Fix, apply limit and set alias for functions

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #9644:
URL: https://github.com/apache/incubator-superset/pull/9644#issuecomment-618910441


   # [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=h1) Report
   > Merging [#9644](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-superset/commit/76764acfc16ef16583dcad30472d93346deaa796&el=desc) will **decrease** coverage by `6.94%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-superset/pull/9644/graphs/tree.svg?width=650&height=150&src=pr&token=KsB0fHcx6l)](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #9644      +/-   ##
   ==========================================
   - Coverage   65.71%   58.76%   -6.95%     
   ==========================================
     Files         574      392     -182     
     Lines       30135    12452   -17683     
     Branches     3066     3066              
   ==========================================
   - Hits        19802     7318   -12484     
   + Misses      10149     4950    -5199     
     Partials      184      184              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | #javascript | `58.76% <ø> (ø)` | |
   | #python | `?` | |
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [superset/utils/dashboard\_import\_export.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdXRpbHMvZGFzaGJvYXJkX2ltcG9ydF9leHBvcnQucHk=) | | |
   | [superset/views/datasource.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvZGF0YXNvdXJjZS5weQ==) | | |
   | [superset/views/api.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvYXBpLnB5) | | |
   | [superset/examples/tabbed\_dashboard.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZXhhbXBsZXMvdGFiYmVkX2Rhc2hib2FyZC5weQ==) | | |
   | [superset/db\_engine\_specs/kylin.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2t5bGluLnB5) | | |
   | [superset/datasets/api.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGF0YXNldHMvYXBpLnB5) | | |
   | [superset/examples/\_\_init\_\_.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZXhhbXBsZXMvX19pbml0X18ucHk=) | | |
   | [superset/db\_engines/hive.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lcy9oaXZlLnB5) | | |
   | [superset/views/dashboard/filters.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvZGFzaGJvYXJkL2ZpbHRlcnMucHk=) | | |
   | [superset/db\_engine\_specs/drill.py](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2RyaWxsLnB5) | | |
   | ... and [170 more](https://codecov.io/gh/apache/incubator-superset/pull/9644/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=footer). Last update [76764ac...419cc7b](https://codecov.io/gh/apache/incubator-superset/pull/9644?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
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


[GitHub] [incubator-superset] villebro commented on a change in pull request #9644: [mssql] Fix, apply limit and set alias for functions

Posted by GitBox <gi...@apache.org>.
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