Skip to content

Commit

Permalink
Use connector registry for metrics (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk authored Mar 16, 2017
1 parent 696678c commit 1b330a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
@@ -1794,6 +1794,7 @@ def sqllab_viz(self):
is_dim = config.get('is_dim', False)
SqlaTable = ConnectorRegistry.sources['table']
TableColumn = SqlaTable.column_cls
SqlMetric = SqlaTable.metric_cls
col = TableColumn(
column_name=column_name,
filterable=is_dim,
@@ -1806,18 +1807,18 @@ def sqllab_viz(self):
agg = config.get('agg')
if agg:
if agg == 'count_distinct':
metrics.append(models.SqlMetric(
metrics.append(SqlMetric(
metric_name="{agg}__{column_name}".format(**locals()),
expression="COUNT(DISTINCT {column_name})"
.format(**locals()),
))
else:
metrics.append(models.SqlMetric(
metrics.append(SqlMetric(
metric_name="{agg}__{column_name}".format(**locals()),
expression="{agg}({column_name})".format(**locals()),
))
if not metrics:
metrics.append(models.SqlMetric(
metrics.append(SqlMetric(
metric_name="count".format(**locals()),
expression="count(*)".format(**locals()),
))

0 comments on commit 1b330a8

Please sign in to comment.