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

fix: handling metadata catalog null & self rel #90

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 14 additions & 9 deletions dbterd/adapters/algos/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,16 @@ def get_table_from_metadata(model_metadata, exposures=[], **kwargs) -> Table:
)

# columns
for column in model_metadata.get("node", {}).get("catalog", {}).get("columns", []):
table.columns.append(
Column(
name=column.get("name", "").lower(),
data_type=column.get("type", "").lower(),
description=column.get("description", ""),
table_catalog = model_metadata.get("node", {}).get("catalog", {})
if table_catalog:
for column in table_catalog.get("columns", []):
table.columns.append(
Column(
name=column.get("name", "").lower(),
data_type=column.get("type", "").lower(),
description=column.get("description", ""),
)
)
)

if not table.columns:
table.columns.append(Column())
Expand Down Expand Up @@ -545,10 +547,13 @@ def get_table_map_from_metadata(test_node, **kwargs) -> List[str]:
if len(test_parents) == 0:
return ["", ""] # return dummies - need to be excluded manually

if len(test_parents) != 2:
if len(test_parents) == 1:
return [test_parents[0], test_parents[0]] # self FK

if len(test_parents) > 2:
logger.debug(f"Collected test parents: {test_parents}")
raise click.BadParameter(
"Relationship test unexpectedly doesn't have 2 parents"
"Relationship test unexpectedly doesn't have >2 parents"
)

test_metadata_to = (
Expand Down
61 changes: 61 additions & 0 deletions tests/unit/adapters/algos/test_test_relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,30 @@ def test_get_tables_from_metadata_w_1_data(
description=None,
),
),
(
{
"node": {
"uniqueId": "model.package.name1",
"database": "db1",
"schema": "sc1",
"name": "name1",
"catalog": None,
}
},
[],
dict(entity_name_format="resource.package.model"),
Table(
name="model.package.name1",
node_name="model.package.name1",
database="db1",
schema="sc1",
columns=[
Column(name="unknown", data_type="unknown", description=""),
],
raw_sql=None,
description=None,
),
),
],
)
def test_get_table_from_metadata(self, model_metadata, exposures, kwargs, expected):
Expand Down Expand Up @@ -761,6 +785,41 @@ def test_get_node_exposures_from_metadata(self, data, kwargs, expected):
)
],
),
(
[
{
"tests": {
"edges": [
{
"node": {
"uniqueId": "test.relationship_1",
"meta": {},
"testMetadata": {
"kwargs": {
"columnName": "coly",
"to": 'ref("x")',
"field": "colx",
}
},
"parents": [
{"uniqueId": "model.p.x"},
],
}
}
]
}
}
],
dict(algo="test_relationship", resource_type=["model"]),
[
Ref(
name="test.relationship_1",
table_map=["model.p.x", "model.p.x"],
column_map=["colx", "coly"],
type="n1",
)
],
),
],
)
def test_get_relationships_from_metadata(self, data, kwargs, expected):
Expand Down Expand Up @@ -789,6 +848,8 @@ def test_get_relationships_from_metadata(self, data, kwargs, expected):
},
"parents": [
{"uniqueId": "model.p.x"},
{"uniqueId": "model.p.y"},
{"uniqueId": "model.p.z"},
],
}
}
Expand Down
Loading