98
98
logger = logging .getLogger (__name__ )
99
99
100
100
VIRTUAL_TABLE_ALIAS = "virtual_table"
101
+ SERIES_LIMIT_SUBQ_ALIAS = "series_limit"
101
102
ADVANCED_DATA_TYPES = config ["ADVANCED_DATA_TYPES" ]
102
103
103
104
@@ -1463,7 +1464,13 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
1463
1464
groupby = groupby or []
1464
1465
rejected_adhoc_filters_columns : list [Union [str , ColumnTyping ]] = []
1465
1466
applied_adhoc_filters_columns : list [Union [str , ColumnTyping ]] = []
1466
- series_column_names = utils .get_column_names (series_columns or [])
1467
+ db_engine_spec = self .db_engine_spec
1468
+ series_column_labels = [
1469
+ db_engine_spec .make_label_compatible (column )
1470
+ for column in utils .get_column_names (
1471
+ columns = series_columns or [],
1472
+ )
1473
+ ]
1467
1474
# deprecated, to be removed in 2.0
1468
1475
if is_timeseries and timeseries_limit :
1469
1476
series_limit = timeseries_limit
@@ -1476,7 +1483,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
1476
1483
template_kwargs ["removed_filters" ] = removed_filters
1477
1484
template_kwargs ["applied_filters" ] = applied_template_filters
1478
1485
template_processor = self .get_template_processor (** template_kwargs )
1479
- db_engine_spec = self .db_engine_spec
1480
1486
prequeries : list [str ] = []
1481
1487
orderby = orderby or []
1482
1488
need_groupby = bool (metrics is not None or groupby )
@@ -1620,8 +1626,8 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
1620
1626
)
1621
1627
groupby_all_columns [outer .name ] = outer
1622
1628
if (
1623
- is_timeseries and not series_column_names
1624
- ) or outer .name in series_column_names :
1629
+ is_timeseries and not series_column_labels
1630
+ ) or outer .name in series_column_labels :
1625
1631
groupby_series_columns [outer .name ] = outer
1626
1632
select_exprs .append (outer )
1627
1633
elif columns :
@@ -2012,7 +2018,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
2012
2018
col_name = db_engine_spec .make_label_compatible (gby_name + "__" )
2013
2019
on_clause .append (gby_obj == sa .column (col_name ))
2014
2020
2015
- tbl = tbl .join (subq .alias (), and_ (* on_clause ))
2021
+ tbl = tbl .join (subq .alias (SERIES_LIMIT_SUBQ_ALIAS ), and_ (* on_clause ))
2016
2022
else :
2017
2023
if series_limit_metric :
2018
2024
orderby = [
0 commit comments