You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "fhyy (via GitHub)" <gi...@apache.org> on 2024/05/12 18:01:04 UTC
[PR] fix: added parameer to optionally rename aliases of aggregated columns used in GROUP BY statments (#28443) [superset]
fhyy opened a new pull request, #28444:
URL: https://github.com/apache/superset/pull/28444
<!---
Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
Example:
fix(dashboard): load charts correctly
-->
### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
Fixed issue #28443
Renamed `db_engine_specs` parameter `allows_alias_to_source_column` to `order_by_allows_alias_to_source_column` and added the new parameter `group_by_allows_alias_to_source_column`.
The previous parameter is used to tell the SQLA generator to rename aliases used in `ORDER BY` statements with aggregations, to ensure that the source column is referenced. Some engines (e.g. Drill) needs to be able to do the same thing for aliases in `GROUP BY` statements.
The new parameter is used to tell the SQLA generator to rename any alias of a source column that is used in an aggregation in a `GROUP BY` statement, to ensure that the source column is referenced.
Added documentation of the new `group_by_allows_alias_to_source_column` parameter, and fixed errors in the documentation of `order_by_allows_alias_to_source_column`/(previously)`allows_alias_to_source_column`
For example this query
```
SELECT length(n_name) AS n_name
...
GROUP BY length(n_name)
```
becomes
```
SELECT length(n_name) AS n_name__
...
GROUP BY length(n_name)
```
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF


### TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
1. Start Superset
2. Navigate to the Superset web application and login
3. Connect to a Drill database
4. Create a dataset of the Drill database
5. Create a chart from that dataset
6. Select visualization type Table with query mode Aggregate
7. Add two columns in the dimensions
8. Aggregate the data of one of the columns (e.g. length(column_a))
9. Press "view query"
10. The query should now contain a GROUP BY statement of an aggregation, and the alias of that aggregation should have "__" at the end of the name.
Example:
```
SELECT length(n_name) AS n_name__
...
GROUP BY length(n_name)
```
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [X] Has associated issue: Fixes #28443
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "fhyy (via GitHub)" <gi...@apache.org>.
fhyy commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2112398325
Thanks for the quick feedback!
@villebro I tried the `_mutate_label` function and it also solves the issue, but I'm not sure if I agree that this is the solution to the actual problem. If I understand that function correctly, it is used to modify labels so that they are compatible with the different engines. An engine could require lowercase letters, or starting with an underscore, etc.
Drill supports the aliases as they are, it just behaves unexpectedly with `GROUP BY` statements as Drill added support for the use of aliases here.
I agree with @john-bodley that the dialects should handle it instead. A boolean parameter isn't as flexible as it may need to be. In this case I would also propose updating the previous `allows_alias_to_source_column` parameter as well.
Thoughts on this?
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2108233500
Thanks @fhyy for the PR. My thinking was the underlying SQLAlchemy dialect should handle the various nuances in terms of how/where aliases are defined.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2106340400
@fhyy thanks for the PR! I believe some other engines have tackled this with the `_mutate_label` function. For instance, you can check how the ClickHouse spec does this (the method being private is slightly confusing, and this should probably be fixed). Can you check if adding similar logic to the Drill spec would solve this issue?
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "fhyy (via GitHub)" <gi...@apache.org>.
fhyy commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2112654527
Yes. The fact that Drill supports aliases in `GROUP BY` makes this example query ambiguous:
```
SELECT length(n_name) AS n_name
FROM
(select * from cp.`tpch/nation.parquet`)
GROUP BY length(n_name)
LIMIT 10;
```
Drill will use the alias `n_name` in `GROUP BY length(n_name)` which results in the actual statement `GROUP BY length(length(n_name))`.
Renaming such aliases solves the problem, but not all aliases needs to be renamed.
You can find more information in issue #28443
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "cgivre (via GitHub)" <gi...@apache.org>.
cgivre commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2112500841
I know I'm a little late to this conversation, and I'm happy to help out where I can, but I'm very unclear as to what the actual issue is. Is the fact that Drill supports aliases in `GROUP BY` breaking things?
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "mbrannstrom (via GitHub)" <gi...@apache.org>.
mbrannstrom commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2144335050
@cgivre : See [my comment on issue 20349](https://github.com/apache/superset/issues/20349#issuecomment-1817480427) for what the problem is with GROUP BY in Apache Drill.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2108806104
CC @cgivre
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2106340721
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/28444?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `46.66667%` with `24 lines` in your changes are missing coverage. Please review.
> Project coverage is 59.59%. Comparing base [(`4720b4f`)](https://app.codecov.io/gh/apache/superset/commit/4720b4f0e672260d7c5d65fc83b84f535bd30cdd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`851f5e5`)](https://app.codecov.io/gh/apache/superset/pull/28444?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 352 commits behind head on master.
| [Files](https://app.codecov.io/gh/apache/superset/pull/28444?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/models/helpers.py](https://app.codecov.io/gh/apache/superset/pull/28444?src=pr&el=tree&filepath=superset%2Fmodels%2Fhelpers.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbW9kZWxzL2hlbHBlcnMucHk=) | 6.25% | [15 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/28444?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/connectors/sqla/models.py](https://app.codecov.io/gh/apache/superset/pull/28444?src=pr&el=tree&filepath=superset%2Fconnectors%2Fsqla%2Fmodels.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29ubmVjdG9ycy9zcWxhL21vZGVscy5weQ==) | 25.00% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/28444?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #28444 +/- ##
===========================================
- Coverage 69.76% 59.59% -10.18%
===========================================
Files 1911 1921 +10
Lines 74994 76157 +1163
Branches 8353 8353
===========================================
- Hits 52316 45382 -6934
- Misses 20629 28726 +8097
Partials 2049 2049
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `49.01% <42.22%> (?)` | |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [python](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `61.81% <46.66%> (-21.11%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/28444/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.74% <46.66%> (+1.96%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/28444?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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
Re: [PR] fix: added parameter to optionally rename aliases of aggregated columns used in GROUP BY statments [superset]
Posted by "fhyy (via GitHub)" <gi...@apache.org>.
fhyy commented on PR #28444:
URL: https://github.com/apache/superset/pull/28444#issuecomment-2205357893
I created a new pull request with a slightly different implementation and based of the newer version:
#29455
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
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