Skip to content

Commit

Permalink
feat(sqla): apply time grain to all temporal groupbys (apache#16318)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored and Emmanuel Bavoux committed Nov 14, 2021
1 parent 5183349 commit d7c88d5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,12 +1069,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
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)
Expand Down

0 comments on commit d7c88d5

Please sign in to comment.