Skip to content

Commit

Permalink
[druid] Excluding refreshing verbose name (#4761)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Apr 5, 2018
1 parent 68999b1 commit df4ff05
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def refresh_metrics(self):
for metric in metrics.values():
dbmetric = dbmetrics.get(metric.metric_name)
if dbmetric:
for attr in ['json', 'metric_type', 'verbose_name']:
for attr in ['json', 'metric_type']:
setattr(dbmetric, attr, getattr(metric, attr))
else:
with db.session.no_autoflush:
Expand Down
49 changes: 43 additions & 6 deletions tests/druid_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,19 @@ def test_refresh_metadata(self, PyDruid):
'double{}'.format(agg.capitalize()),
)

# Augment a metric.
metadata = SEGMENT_METADATA[:]
metadata[0]['columns']['metric1']['type'] = 'LONG'
instance = PyDruid.return_value
instance.segment_metadata.return_value = metadata
cluster.refresh_datasources()
@patch('superset.connectors.druid.models.PyDruid')
def test_refresh_metadata_augment_type(self, PyDruid):
self.login(username='admin')
cluster = self.get_cluster(PyDruid)
cluster.refresh_datasources()

metadata = SEGMENT_METADATA[:]
metadata[0]['columns']['metric1']['type'] = 'LONG'
instance = PyDruid.return_value
instance.segment_metadata.return_value = metadata
cluster.refresh_datasources()

for i, datasource in enumerate(cluster.datasources):
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
Expand All @@ -397,6 +403,37 @@ def test_refresh_metadata(self, PyDruid):
'long{}'.format(agg.capitalize()),
)

@patch('superset.connectors.druid.models.PyDruid')
def test_refresh_metadata_augment_verbose_name(self, PyDruid):
self.login(username='admin')
cluster = self.get_cluster(PyDruid)
cluster.refresh_datasources()

for i, datasource in enumerate(cluster.datasources):
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)

for metric in metrics:
metric.verbose_name = metric.metric_name

db.session.commit()

# The verbose name should not change during a refresh.
cluster.refresh_datasources()

for i, datasource in enumerate(cluster.datasources):
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)

for metric in metrics:
self.assertEqual(metric.verbose_name, metric.metric_name)

def test_urls(self):
cluster = self.get_test_cluster_obj()
self.assertEquals(
Expand Down

0 comments on commit df4ff05

Please sign in to comment.