From 2b54029f439ae62de7fa9ad563a445a7f2f62e15 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Tue, 26 Oct 2021 16:53:06 -0700 Subject: [PATCH 1/2] Revert "feat(sqla): apply time grain to all temporal groupbys (#16318)" This reverts commit 9075e4206c95a868206cc264dad4efd6e962c1d1. --- superset/connectors/sqla/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index 1f68dea2be3de..cd93d11969a92 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -1087,12 +1087,12 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma columns = groupby or columns for selected in columns: # if groupby field/expr equals granularity field/expr - table_col = columns_by_name.get(selected) - if table_col and table_col.type_generic == GenericDataType.TEMPORAL: - outer = table_col.get_timestamp_expression(time_grain, selected) + if selected == granularity: + sqla_col = columns_by_name[selected] + outer = sqla_col.get_timestamp_expression(time_grain, selected) # if groupby field equals a selected column - elif table_col: - outer = table_col.get_sqla_col() + elif selected in columns_by_name: + outer = columns_by_name[selected].get_sqla_col() else: outer = literal_column(f"({selected})") outer = self.make_sqla_column_compatible(outer, selected) From d158742a9e984db6f210147c950587e291293c7f Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Thu, 28 Oct 2021 14:06:41 -0700 Subject: [PATCH 2/2] Update models.py --- superset/connectors/sqla/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index 02b85c2c0163e..c3d440a624f64 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -1094,7 +1094,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma # if groupby field/expr equals granularity field/expr if selected == granularity: sqla_col = columns_by_name[selected] - outer = table_col.get_timestamp_expression( + outer = sqla_col.get_timestamp_expression( time_grain=time_grain, label=selected, template_processor=template_processor,