Skip to content

Commit

Permalink
Adding the MetricsControl to the timeseries_limit_metric field
Browse files Browse the repository at this point in the history
  • Loading branch information
michellethomas committed May 31, 2018
1 parent d322e48 commit 6f05b48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions superset/assets/src/explore/controls.jsx
Expand Up @@ -959,12 +959,14 @@ export const controls = {
},

timeseries_limit_metric: {
type: 'SelectControl',
type: 'MetricsControl',
label: t('Sort By'),
default: null,
description: t('Metric used to define the top series'),
mapStateToProps: state => ({
choices: (state.datasource) ? state.datasource.metrics_combo : [],
columns: state.datasource ? state.datasource.columns : [],
savedMetrics: state.datasource ? state.datasource.metrics : [],
datasourceType: state.datasource && state.datasource.type,
}),
},

Expand Down
9 changes: 7 additions & 2 deletions superset/connectors/druid/models.py
Expand Up @@ -1148,6 +1148,11 @@ def run_query( # noqa / druid
metric['column']['type'].upper() == 'FLOAT'
):
metric['column']['type'] = 'DOUBLE'
if (
utils.is_adhoc_metric(timeseries_limit_metric) and
timeseries_limit_metric['column']['type'].upper() == 'FLOAT'
):
timeseries_limit_metric['column']['type'] = 'DOUBLE'

aggregations, post_aggs = DruidDatasource.metrics_and_post_aggs(
metrics,
Expand Down Expand Up @@ -1203,7 +1208,7 @@ def run_query( # noqa / druid
logging.info('Running two-phase topn query for dimension [{}]'.format(dim))
pre_qry = deepcopy(qry)
if timeseries_limit_metric:
order_by = timeseries_limit_metric
order_by = utils.get_metric_name(timeseries_limit_metric)
aggs_dict, post_aggs_dict = DruidDatasource.metrics_and_post_aggs(
[timeseries_limit_metric],
metrics_dict)
Expand Down Expand Up @@ -1272,7 +1277,7 @@ def run_query( # noqa / druid
order_by = pre_qry_dims[0]

if timeseries_limit_metric:
order_by = timeseries_limit_metric
order_by = utils.get_metric_name(timeseries_limit_metric)
aggs_dict, post_aggs_dict = DruidDatasource.metrics_and_post_aggs(
[timeseries_limit_metric],
metrics_dict)
Expand Down
11 changes: 9 additions & 2 deletions superset/connectors/sqla/models.py
Expand Up @@ -675,8 +675,15 @@ def get_sqla_query( # sqla

ob = inner_main_metric_expr
if timeseries_limit_metric:
timeseries_limit_metric = metrics_dict.get(timeseries_limit_metric)
ob = timeseries_limit_metric.sqla_col
if utils.is_adhoc_metric(timeseries_limit_metric):
ob = self.adhoc_metric_to_sa(timeseries_limit_metric, cols)
elif timeseries_limit_metric in metrics_dict:
timeseries_limit_metric = metrics_dict.get(
timeseries_limit_metric,
)
ob = timeseries_limit_metric.sqla_col
else:
raise Exception(_("Metric '{}' is not valid".format(m)))
direction = desc if order_desc else asc
subq = subq.order_by(direction(ob))
subq = subq.limit(timeseries_limit)
Expand Down

0 comments on commit 6f05b48

Please sign in to comment.