-
Notifications
You must be signed in to change notification settings - Fork 13.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: added parameter to rename aliases of aggregated columns used in GROUP BY statments #29455
base: master
Are you sure you want to change the base?
Conversation
The value is true if the engine is able to pick the source column for aggregation clauses used in ORDER BY when a column in SELECT has an alias that is the same as a source column.
* Renamed attribute allows_alias_to_source_column to order_by_allows_alias_to_source_column * Added attribute group_by_allows_alias_to_source_column * Rename aliases for source columns if used in GROUP BY and if group_by_allows_alias_to_source_column is false
The new name is shorter but also more true to the actual usage. Updated documentation and implementation.
Thanks for this! Running CI 🤞 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #29455 +/- ##
===========================================
+ Coverage 60.48% 83.85% +23.36%
===========================================
Files 1931 519 -1412
Lines 76236 37440 -38796
Branches 8568 0 -8568
===========================================
- Hits 46114 31395 -14719
+ Misses 28017 6045 -21972
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Just the comment that this works after merging to our branch (we have Apache Drill setup to call our proprietary db that can interface in Mongo syntax). I know there are pending 340 PR, want to add some plus points on merging this. Edit:
SELECT
NEARESTDATE(`Timestamp`, 'DAY') AS `Timestamp__`,
`DB User Name` AS `DB User Name`,
count(DISTINCT `Timestamp`) AS `COUNT_DISTINCT(Timestamp)`
FROM `mongo`.`sonar_log`.`audit_log`
GROUP BY
NEARESTDATE(`Timestamp`, 'DAY'),
`DB User Name`
ORDER BY
`Timestamp` ASC,
`DB User Name` ASC
LIMIT 10000; |
Hi @joeyJsonar, can you clarify what you mean by "Heatmap is not working" in this example? The query does not seem to use any aliases that would break it. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have a mechanism for this in the BaseEngineSpec._mutate_label
method Apologies for the name of it, but it does precisely this. For instance, ClickHouse has the same issue, and it's solved by suffixing a snippet of the MD5 of the original label name.
SUMMARY
Follow up PR after #28444.
The only notable change after that PR is that I shortened the parameter names to properly reflect the usage and to fit within the 30 character limit. This name change also inverts the meaning of the parameter and thus the usage has also been inverted everywhere.
Fixes issue #28443
Renamed
db_engine_specs
parameterallows_alias_to_source_column
toorder_by_require_unique_alias
and added the new parametergroup_by_require_unique_alias
. This new name also inverts the meaning of the parameter, but properly reflects its function.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 inGROUP 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.For example this query
becomes
This ensures that the source column
n_name
is used in thelength(n_name)
statement.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
The documentation of the new
group_by_require_unique_alias
parameter has been added, and errors in the documentation oforder_by_require_unique_alias
/(previously)allows_alias_to_source_column
has been fixed.TESTING INSTRUCTIONS
Example:
ADDITIONAL INFORMATION