Skip to content

Commit

Permalink
Merge pull request preset-io#3 from shrodingers/feat/datasetUnique
Browse files Browse the repository at this point in the history
Feat/dataset unique
  • Loading branch information
CyprienAlle committed Mar 6, 2023
2 parents 666bc92 + 95b60b6 commit 858f0d3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/preset_cli/cli/superset/sync/dbt/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ def sync_datasets( # pylint: disable=too-many-locals, too-many-branches, too-ma
for model in models:
filters = {
"database": OneToMany(database["id"]),
"schema": model["schema"],
"table_name": model.get("alias") or model["name"],
}
existing = client.get_datasets(**filters)
if len(existing) > 1:
unique_id = model["unique_id"]
existing = [
item
for item in existing
if unique_id == json.loads(item["extra"])["unique_id"]
]
if len(existing) > 1:
raise Exception("More than one dataset found")

Expand Down Expand Up @@ -174,6 +180,7 @@ def get_deps_metrics(metric):
# update dataset clearing metrics...
update = {
"description": model.get("description", ""),
"schema": model["schema"],
"extra": json.dumps(extra),
"is_managed_externally": disallow_edits,
"metrics": [],
Expand Down

0 comments on commit 858f0d3

Please sign in to comment.