Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for aliased models and source blocks #17

Merged
merged 7 commits into from
May 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions dbtmetabase/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,35 @@ def read_models(self, includes=[], excludes=[]) -> list:
mb_models = []

for path in (Path(self.project_path) / "models").rglob("*.yml"):
logging.info(
"Processing model: %s",
path
)
with open(path, "r") as stream:
schema = yaml.safe_load(stream)
if schema is None:
z3z1ma marked this conversation as resolved.
Show resolved Hide resolved
logging.warn(
"Skipping empty or invalid YAML: %s",
path
)
continue
for model in schema.get("models", []):
name = model["name"]
name = model.get("identifier", model["name"])
logging.info(
"Model: %s",
name
)
if (not includes or name in includes) and (name not in excludes):
mb_models.append(self.read_model(model))
for source in schema.get("sources", []):
for model in source.get("tables", []):
name = model.get("identifier", model["name"])
logging.info(
"Source: %s",
name
)
if (not includes or name in includes) and (name not in excludes):
mb_models.append(self.read_model(model))

return mb_models

Expand All @@ -61,7 +84,7 @@ def read_model(self, model: dict) -> dict:
mb_columns.append(self.read_column(column))

return {
"name": model["name"].upper(),
"name": model.get("identifier", model["name"]).upper(),
"description": model.get("description"),
"columns": mb_columns,
}
Expand All @@ -86,8 +109,8 @@ def read_column(self, column: dict) -> dict:
if "relationships" in test:
relationships = test["relationships"]
mb_column["semantic_type"] = "type/FK"
mb_column["fk_target_table"] = self.parse_ref(
relationships["to"]
mb_column["fk_target_table"] = column.get("meta", {}).get(
"metabase.fk_ref", self.parse_ref(relationships["to"])
).upper()
mb_column["fk_target_field"] = relationships["field"].upper()

Expand Down