FrancescoCastaldi commented on issue #45738: URL: https://github.com/apache/superset/issues/45738#issuecomment-6524016545
### Root Cause Analysis & Solution In `superset/models/helpers.py:ExploreMixin._get_series_limit_clause`, the join between the main query and the series limit subquery is constructed as: ```python on_clause.append(gby_obj == sa.column(col_name)) ``` In ClickHouse, an unqualified column name in an `ON` clause resolves preferentially against the outer query's `SELECT` alias (for example `upper(label) AS app__`). Because `col_name` matches the alias name, the join condition becomes `upper(label) = upper(label)` (a tautology). This causes an inadvertent cross-join that multiplies every metric value by the total number of series. #### Solution Qualify the join column with the subquery alias: ```python subq_alias = subq.alias(SERIES_LIMIT_SUBQ_ALIAS) on_clause.append(gby_obj == subq_alias.c[col_name]) ``` This forces ClickHouse to evaluate `ON upper(label) = series_limit.app__`, preventing alias collisions. Verified with unit tests in `tests/unit_tests/models/helpers_test.py` and committed to branch `fix/community-unanswered-issues` (commit `587f3d023ba`) at https://github.com/FrancescoCastaldi/superset/tree/fix/community-unanswered-issues. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
