Skip to content

Commit

Permalink
Handle Time at query_obj generation time (#3236)
Browse files Browse the repository at this point in the history
As opposed to in the within itself
  • Loading branch information
mistercrunch authored Aug 3, 2017
1 parent 5278b53 commit 4c3313b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 0 additions & 4 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,6 @@ def run_query( # noqa / druid
# TODO refactor into using a TBD Query object
client = client or self.cluster.get_pydruid_client()

if DTTM_ALIAS in groupby:
groupby.remove(DTTM_ALIAS)
is_timeseries = True

if not is_timeseries:
granularity = 'all'
inner_from_dttm = inner_from_dttm or from_dttm
Expand Down
4 changes: 0 additions & 4 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,6 @@ def get_sqla_query( # sqla
template_processor = self.get_template_processor(**template_kwargs)
db_engine_spec = self.database.db_engine_spec

if DTTM_ALIAS in groupby:
groupby.remove(DTTM_ALIAS)
is_timeseries = True

# For backward compatibility
if granularity not in self.dttm_cols:
granularity = self.main_dttm_col
Expand Down
21 changes: 13 additions & 8 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def query_obj(self):
form_data = self.form_data
groupby = form_data.get("groupby") or []
metrics = form_data.get("metrics") or []
columns = form_data.get("columns") or []
groupby = list(set(groupby + columns))

is_timeseries = self.is_timeseries
if DTTM_ALIAS in groupby:
groupby.remove(DTTM_ALIAS)
is_timeseries = True

# extra_filters are temporary/contextual filters that are external
# to the slice definition. We use those for dynamic interactive
Expand Down Expand Up @@ -173,7 +180,7 @@ def query_obj(self):
'granularity': granularity,
'from_dttm': from_dttm,
'to_dttm': to_dttm,
'is_timeseries': self.is_timeseries,
'is_timeseries': is_timeseries,
'groupby': groupby,
'metrics': metrics,
'row_limit': row_limit,
Expand Down Expand Up @@ -385,9 +392,7 @@ def query_obj(self):
if (
any(v in groupby for v in columns) or
any(v in columns for v in groupby)):
raise Exception("groupby and columns can't overlap")

d['groupby'] = list(set(groupby) | set(columns))
raise Exception(""""Group By" and "Columns" can't overlap""")
return d

def get_data(self, df):
Expand Down Expand Up @@ -1082,10 +1087,10 @@ class DistributionBarViz(DistributionPieViz):
def query_obj(self):
d = super(DistributionBarViz, self).query_obj() # noqa
fd = self.form_data
gb = fd.get('groupby') or []
cols = fd.get('columns') or []
d['groupby'] = set(gb + cols)
if len(d['groupby']) < len(gb) + len(cols):
if (
len(self.groupby) <
len(fd.get('groupby') or []) + len(fd.get('columns') or [])
):
raise Exception("Can't have overlap between Series and Breakdowns")
if not self.metrics:
raise Exception("Pick at least one metric")
Expand Down

0 comments on commit 4c3313b

Please sign in to comment.