Skip to content

Commit

Permalink
Clean up the druid sync api. (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk authored Sep 14, 2016
1 parent 2e6b4b1 commit a871ee7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
7 changes: 4 additions & 3 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1388,9 +1388,10 @@ def sync_druid_source(self):
"dimensions": ["affiliate_id", "campaign", "first_seen"]
}
"""
druid_config = json.loads(request.form.get('config'))
user_name = request.form.get('user')
cluster_name = request.form.get('cluster')
payload = request.get_json(force=True)
druid_config = payload['config']
user_name = payload['user']
cluster_name = payload['cluster']

user = sm.find_user(username=user_name)
if not user:
Expand Down
58 changes: 30 additions & 28 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,24 @@ def test_druid_sync_from_config(self):
db.session.commit()

cfg = {
"name": "test_click",
"dimensions": ["affiliate_id", "campaign", "first_seen"],
"metrics_spec": [{"type": "count", "name": "count"},
{"type": "sum", "name": "sum"}],
"batch_ingestion": {
"sql": "SELECT * FROM clicks WHERE d='{{ ds }}'",
"ts_column": "d",
"sources": [{
"table": "clicks",
"partition": "d='{{ ds }}'"
}]
"user": "admin",
"cluster": "new_druid",
"config": {
"name": "test_click",
"dimensions": ["affiliate_id", "campaign", "first_seen"],
"metrics_spec": [{"type": "count", "name": "count"},
{"type": "sum", "name": "sum"}],
"batch_ingestion": {
"sql": "SELECT * FROM clicks WHERE d='{{ ds }}'",
"ts_column": "d",
"sources": [{
"table": "clicks",
"partition": "d='{{ ds }}'"
}]
}
}
}
resp = self.client.post(
'/caravel/sync_druid/', data=dict(
config=json.dumps(cfg), user="admin", cluster="new_druid"))
resp = self.client.post('/caravel/sync_druid/', data=json.dumps(cfg))

druid_ds = db.session.query(DruidDatasource).filter_by(
datasource_name="test_click").first()
Expand All @@ -243,10 +245,8 @@ def test_druid_sync_from_config(self):
["count", "sum"])
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"))
# 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(
Expand All @@ -255,18 +255,20 @@ def test_druid_sync_from_config(self):
["count", "sum"])
assert resp.status_code == 201

# datasource exists, not changes required
# datasource exists, add new metrics and dimentions
cfg = {
"name": "test_click",
"dimensions": ["affiliate_id", "second_seen"],
"metrics_spec": [
{"type": "bla", "name": "sum"},
{"type": "unique", "name": "unique"}
],
"user": "admin",
"cluster": "new_druid",
"config": {
"name": "test_click",
"dimensions": ["affiliate_id", "second_seen"],
"metrics_spec": [
{"type": "bla", "name": "sum"},
{"type": "unique", "name": "unique"}
],
}
}
resp = self.client.post(
'/caravel/sync_druid/', data=dict(
config=json.dumps(cfg), user="admin", cluster="new_druid"))
resp = self.client.post('/caravel/sync_druid/', data=json.dumps(cfg))
druid_ds = db.session.query(DruidDatasource).filter_by(
datasource_name="test_click").first()
# columns and metrics are not deleted if config is changed as
Expand Down

0 comments on commit a871ee7

Please sign in to comment.