You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2021/08/18 08:48:35 UTC

[superset] branch master updated: feat(sqla): apply time grain to all temporal groupbys (#16318)

This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 9075e42  feat(sqla): apply time grain to all temporal groupbys (#16318)
9075e42 is described below

commit 9075e4206c95a868206cc264dad4efd6e962c1d1
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Wed Aug 18 11:47:08 2021 +0300

    feat(sqla): apply time grain to all temporal groupbys (#16318)
---
 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 fd43010..163648f 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -1069,12 +1069,12 @@ class SqlaTable(  # pylint: disable=too-many-public-methods,too-many-instance-at
             columns = groupby or columns
             for selected in columns:
                 # if groupby field/expr equals granularity field/expr
-                if selected == granularity:
-                    sqla_col = columns_by_name[selected]
-                    outer = sqla_col.get_timestamp_expression(time_grain, selected)
+                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 groupby field equals a selected column
-                elif selected in columns_by_name:
-                    outer = columns_by_name[selected].get_sqla_col()
+                elif table_col:
+                    outer = table_col.get_sqla_col()
                 else:
                     outer = literal_column(f"({selected})")
                     outer = self.make_sqla_column_compatible(outer, selected)