Skip to content
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: Chart series limit doesn't work for some databases #25150

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
logger = logging.getLogger(__name__)

VIRTUAL_TABLE_ALIAS = "virtual_table"
SERIES_LIMIT_SUBQ_ALIAS = "series_limit"
ADVANCED_DATA_TYPES = config["ADVANCED_DATA_TYPES"]


Expand Down Expand Up @@ -1463,7 +1464,13 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
groupby = groupby or []
rejected_adhoc_filters_columns: list[Union[str, ColumnTyping]] = []
applied_adhoc_filters_columns: list[Union[str, ColumnTyping]] = []
series_column_names = utils.get_column_names(series_columns or [])
db_engine_spec = self.db_engine_spec
series_column_labels = [
db_engine_spec.make_label_compatible(column)
for column in utils.get_column_names(
columns=series_columns or [],
)
]
# deprecated, to be removed in 2.0
if is_timeseries and timeseries_limit:
series_limit = timeseries_limit
Expand All @@ -1476,7 +1483,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
template_kwargs["removed_filters"] = removed_filters
template_kwargs["applied_filters"] = applied_template_filters
template_processor = self.get_template_processor(**template_kwargs)
db_engine_spec = self.db_engine_spec
prequeries: list[str] = []
orderby = orderby or []
need_groupby = bool(metrics is not None or groupby)
Expand Down Expand Up @@ -1620,8 +1626,8 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
)
groupby_all_columns[outer.name] = outer
if (
is_timeseries and not series_column_names
) or outer.name in series_column_names:
is_timeseries and not series_column_labels
) or outer.name in series_column_labels:
groupby_series_columns[outer.name] = outer
select_exprs.append(outer)
elif columns:
Expand Down Expand Up @@ -2012,7 +2018,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
col_name = db_engine_spec.make_label_compatible(gby_name + "__")
on_clause.append(gby_obj == sa.column(col_name))

tbl = tbl.join(subq.alias(), and_(*on_clause))
tbl = tbl.join(subq.alias(SERIES_LIMIT_SUBQ_ALIAS), and_(*on_clause))
else:
if series_limit_metric:
orderby = [
Expand Down
Loading