mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
Use connector registry for metrics (#2420)
This commit is contained in:
parent
696678c981
commit
1b330a8c55
@ -1794,6 +1794,7 @@ class Superset(BaseSupersetView):
|
||||
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 @@ class Superset(BaseSupersetView):
|
||||
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()),
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user