mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
[sqllab] Fix sql expression bug with count distinct metrics (#1805)
* Return error message when metrics are not valid * Fix bug with count distinct expression * Fixed codeclimate issue
This commit is contained in:
parent
84a3b55912
commit
638f27c2df
@ -1019,7 +1019,9 @@ class SqlaTable(Model, Queryable, AuditMixinNullable, ImportMixin):
|
||||
raise Exception(_(
|
||||
"Datetime column not provided as part table configuration "
|
||||
"and is required by this type of chart"))
|
||||
|
||||
for m in metrics:
|
||||
if m not in metrics_dict:
|
||||
raise Exception(_("Metric '{}' is not valid".format(m)))
|
||||
metrics_exprs = [metrics_dict.get(m).sqla_col for m in metrics]
|
||||
timeseries_limit_metric = metrics_dict.get(timeseries_limit_metric)
|
||||
timeseries_limit_metric_expr = None
|
||||
|
@ -2185,10 +2185,17 @@ class Superset(BaseSupersetView):
|
||||
dims.append(col)
|
||||
agg = config.get('agg')
|
||||
if agg:
|
||||
metrics.append(models.SqlMetric(
|
||||
metric_name="{agg}__{column_name}".format(**locals()),
|
||||
expression="{agg}({column_name})".format(**locals()),
|
||||
))
|
||||
if agg == 'count_distinct':
|
||||
metrics.append(models.SqlMetric(
|
||||
metric_name="{agg}__{column_name}".format(**locals()),
|
||||
expression="COUNT(DISTINCT {column_name})"
|
||||
.format(**locals()),
|
||||
))
|
||||
else:
|
||||
metrics.append(models.SqlMetric(
|
||||
metric_name="{agg}__{column_name}".format(**locals()),
|
||||
expression="{agg}({column_name})".format(**locals()),
|
||||
))
|
||||
if not metrics:
|
||||
metrics.append(models.SqlMetric(
|
||||
metric_name="count".format(**locals()),
|
||||
|
Loading…
Reference in New Issue
Block a user