mirror of https://github.com/apache/superset.git
Clean up the druid sync api. (#1101)
This commit is contained in:
parent
2e6b4b121f
commit
a871ee7858
|
@ -1388,9 +1388,10 @@ class Caravel(BaseCaravelView):
|
||||||
"dimensions": ["affiliate_id", "campaign", "first_seen"]
|
"dimensions": ["affiliate_id", "campaign", "first_seen"]
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
druid_config = json.loads(request.form.get('config'))
|
payload = request.get_json(force=True)
|
||||||
user_name = request.form.get('user')
|
druid_config = payload['config']
|
||||||
cluster_name = request.form.get('cluster')
|
user_name = payload['user']
|
||||||
|
cluster_name = payload['cluster']
|
||||||
|
|
||||||
user = sm.find_user(username=user_name)
|
user = sm.find_user(username=user_name)
|
||||||
if not user:
|
if not user:
|
||||||
|
|
|
@ -218,6 +218,9 @@ class CoreTests(CaravelTestCase):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
cfg = {
|
cfg = {
|
||||||
|
"user": "admin",
|
||||||
|
"cluster": "new_druid",
|
||||||
|
"config": {
|
||||||
"name": "test_click",
|
"name": "test_click",
|
||||||
"dimensions": ["affiliate_id", "campaign", "first_seen"],
|
"dimensions": ["affiliate_id", "campaign", "first_seen"],
|
||||||
"metrics_spec": [{"type": "count", "name": "count"},
|
"metrics_spec": [{"type": "count", "name": "count"},
|
||||||
|
@ -231,9 +234,8 @@ class CoreTests(CaravelTestCase):
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp = self.client.post(
|
}
|
||||||
'/caravel/sync_druid/', data=dict(
|
resp = self.client.post('/caravel/sync_druid/', data=json.dumps(cfg))
|
||||||
config=json.dumps(cfg), user="admin", cluster="new_druid"))
|
|
||||||
|
|
||||||
druid_ds = db.session.query(DruidDatasource).filter_by(
|
druid_ds = db.session.query(DruidDatasource).filter_by(
|
||||||
datasource_name="test_click").first()
|
datasource_name="test_click").first()
|
||||||
|
@ -243,20 +245,21 @@ class CoreTests(CaravelTestCase):
|
||||||
["count", "sum"])
|
["count", "sum"])
|
||||||
assert resp.status_code == 201
|
assert resp.status_code == 201
|
||||||
|
|
||||||
# Datasource exists, not changes required
|
|
||||||
resp = self.client.post(
|
|
||||||
'/caravel/sync_druid/', data=dict(
|
|
||||||
config=json.dumps(cfg), user="admin", cluster="new_druid"))
|
|
||||||
druid_ds = db.session.query(DruidDatasource).filter_by(
|
|
||||||
datasource_name="test_click").first()
|
|
||||||
assert set([c.column_name for c in druid_ds.columns]) == set(
|
|
||||||
["affiliate_id", "campaign", "first_seen"])
|
|
||||||
assert set([m.metric_name for m in druid_ds.metrics]) == set(
|
|
||||||
["count", "sum"])
|
|
||||||
assert resp.status_code == 201
|
|
||||||
|
|
||||||
# datasource exists, not changes required
|
# datasource exists, not changes required
|
||||||
|
resp = self.client.post('/caravel/sync_druid/', data=json.dumps(cfg))
|
||||||
|
druid_ds = db.session.query(DruidDatasource).filter_by(
|
||||||
|
datasource_name="test_click").first()
|
||||||
|
assert set([c.column_name for c in druid_ds.columns]) == set(
|
||||||
|
["affiliate_id", "campaign", "first_seen"])
|
||||||
|
assert set([m.metric_name for m in druid_ds.metrics]) == set(
|
||||||
|
["count", "sum"])
|
||||||
|
assert resp.status_code == 201
|
||||||
|
|
||||||
|
# datasource exists, add new metrics and dimentions
|
||||||
cfg = {
|
cfg = {
|
||||||
|
"user": "admin",
|
||||||
|
"cluster": "new_druid",
|
||||||
|
"config": {
|
||||||
"name": "test_click",
|
"name": "test_click",
|
||||||
"dimensions": ["affiliate_id", "second_seen"],
|
"dimensions": ["affiliate_id", "second_seen"],
|
||||||
"metrics_spec": [
|
"metrics_spec": [
|
||||||
|
@ -264,9 +267,8 @@ class CoreTests(CaravelTestCase):
|
||||||
{"type": "unique", "name": "unique"}
|
{"type": "unique", "name": "unique"}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
resp = self.client.post(
|
}
|
||||||
'/caravel/sync_druid/', data=dict(
|
resp = self.client.post('/caravel/sync_druid/', data=json.dumps(cfg))
|
||||||
config=json.dumps(cfg), user="admin", cluster="new_druid"))
|
|
||||||
druid_ds = db.session.query(DruidDatasource).filter_by(
|
druid_ds = db.session.query(DruidDatasource).filter_by(
|
||||||
datasource_name="test_click").first()
|
datasource_name="test_click").first()
|
||||||
# columns and metrics are not deleted if config is changed as
|
# columns and metrics are not deleted if config is changed as
|
||||||
|
|
Loading…
Reference in New Issue