Skip to content

Commit

Permalink
dttm handling, codeclimate tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
RichRadics committed May 3, 2017
1 parent 2e5c34e commit 4c74d1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
17 changes: 8 additions & 9 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,12 @@ def visit_column(element, compiler, **kw):
select_exprs += [timestamp]
groupby_exprs += [timestamp]

# Use all dttm columns to support index with secondary dttm columns
dttm_col_all = False
if hasattr(self.database.db_engine_spec, 'time_secondary_columns'):
dttm_col_all = self.database.db_engine_spec.time_secondary_columns
if dttm_col_all:
for c in self.dttm_cols:
if c in cols:
time_filters.append(cols[c].get_time_filter(from_dttm, to_dttm))
# Use main dttm column to support index with secondary dttm columns
if self.database.db_engine_spec.time_secondary_columns and \
self.main_dttm_col in self.dttm_cols and \
self.main_dttm_col != dttm_col.column_name:
time_filters.append(cols[self.main_dttm_col].
get_time_filter(from_dttm, to_dttm))
time_filters.append(dttm_col.get_time_filter(from_dttm, to_dttm))

select_exprs += metrics_exprs
Expand Down Expand Up @@ -534,7 +532,8 @@ def visit_column(element, compiler, **kw):

qry = qry.limit(row_limit)

if is_timeseries and timeseries_limit and groupby and not time_groupby_inline:
if is_timeseries and \
timeseries_limit and groupby and not time_groupby_inline:
# some sql dialects require for order by expressions
# to also be in the select clause -- others, e.g. vertica,
# require a unique inner alias
Expand Down
5 changes: 3 additions & 2 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ def convert_dttm(cls, target_type, dttm):
def epoch_to_dttm(cls):
return "from_unixtime({col})"

class ClickHouseEngineSpec(BaseEngineSpec):

class ClickHouseEngineSpec(BaseEngineSpec):
"""Dialect for ClickHouse analytical DB."""

engine = 'clickhouse'
Expand Down Expand Up @@ -901,7 +901,8 @@ def convert_dttm(cls, target_type, dttm):
if tt == 'DATE':
return "toDate('{}')".format(dttm.strftime('%Y-%m-%d'))
if tt == 'DATETIME':
return "toDateTime('{}')".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))
return "toDateTime('{}')".format(
dttm.strftime('%Y-%m-%d %H:%M:%S'))
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))

engines = {
Expand Down
4 changes: 3 additions & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def query_obj(self):
# [column_name in list_of_values]. `__` prefix is there to avoid
# potential conflicts with column that would be named `from` or `to`
since = (
extra_filters.get('__from') or form_data.get("since") or config.get("SUPERSET_DEFAULT_SINCE", "1 year ago")
extra_filters.get('__from') or
form_data.get("since") or
config.get("SUPERSET_DEFAULT_SINCE", "1 year ago")
)

from_dttm = utils.parse_human_datetime(since)
Expand Down

0 comments on commit 4c74d1a

Please sign in to comment.