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 4 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
19 changes: 15 additions & 4 deletions dbtmetabase/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ def read_models(self, includes=[], excludes=[]) -> list:
mb_models = []

for path in (Path(self.project_path) / "models").rglob("*.yml"):
logging.info(path)
z3z1ma marked this conversation as resolved.
Show resolved Hide resolved
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(f"SKIPPING EMPTY/INVALID YML: {path}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use all-caps in logs, it's inconsistent with other logs. Also no need for f-strings in logging statements, it takes arguments:

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"])
print("MODEL", name)
z3z1ma marked this conversation as resolved.
Show resolved Hide resolved
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"])
print("SOURCE", 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 +72,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 +97,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