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

feat(ingest): extract dbt meta fields #2876

Merged
merged 3 commits into from
Jul 13, 2021
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
8 changes: 7 additions & 1 deletion metadata-ingestion/src/datahub/ingestion/source/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DBTNode:
columns: List[DBTColumn] = field(default_factory=list)
upstream_urns: List[str] = field(default_factory=list)

meta: Dict[str, Any] = field(default_factory=dict)

def __repr__(self):
fields = tuple("{}={}".format(k, v) for k, v in self.__dict__.items())
return self.__class__.__name__ + str(tuple(sorted(fields))).replace("'", "")
Expand Down Expand Up @@ -177,6 +179,7 @@ def extract_dbt_entities(
target_platform,
environment,
),
meta=node.get("meta", {}),
)

# overwrite columns from catalog
Expand Down Expand Up @@ -259,8 +262,11 @@ def get_urn_from_dbtNode(

def get_custom_properties(node: DBTNode) -> Dict[str, str]:

custom_properties = {}
# initialize custom properties to node's meta props
# (dbt-native node properties)
custom_properties = node.meta

# additional node attributes to extract to custom properties
node_attributes = ["node_type", "materialization", "dbt_file_path", "catalog_type"]

for attribute in node_attributes:
Expand Down
4 changes: 2 additions & 2 deletions metadata-ingestion/tests/integration/dbt/dbt_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"dbt_schema_version": "https://schemas.getdbt.com/dbt/catalog/v1.json",
"dbt_version": "0.19.1",
"env": {},
"generated_at": "2021-06-21T17:28:04.980076Z",
"invocation_id": "a878f3a5-ecf3-44b1-94ac-4334c92ca3f6"
"generated_at": "2021-07-13T18:38:17.650799Z",
"invocation_id": "a0290787-2b80-46c6-a3b7-bf882f654ff3"
},
"nodes": {
"model.sample_dbt.monthly_billing_with_cust": {
Expand Down
18 changes: 15 additions & 3 deletions metadata-ingestion/tests/integration/dbt/dbt_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3359,7 +3359,11 @@
"identifier": "actor",
"loaded_at_field": "last_update",
"loader": "",
"meta": {},
"meta": {
"model_maturity": "in dev",
"owner": "@alice",
"some_other_property": "test 1"
},
"name": "actor",
"original_file_path": "models/base.yml",
"package_name": "sample_dbt",
Expand Down Expand Up @@ -3559,7 +3563,11 @@
"identifier": "country",
"loaded_at_field": "last_update",
"loader": "",
"meta": {},
"meta": {
"model_maturity": "in prod",
"owner": "@bob",
"some_other_property": "test 2"
},
"name": "country",
"original_file_path": "models/base.yml",
"package_name": "sample_dbt",
Expand Down Expand Up @@ -3709,7 +3717,11 @@
"identifier": "payment_p2020_02",
"loaded_at_field": "payment_date",
"loader": "",
"meta": {},
"meta": {
"model_maturity": "in prod",
"owner": "@charles",
"some_other_property": "test 3"
},
"name": "payment_p2020_02",
"original_file_path": "models/base.yml",
"package_name": "sample_dbt",
Expand Down
9 changes: 9 additions & 0 deletions metadata-ingestion/tests/integration/dbt/dbt_mces_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@
{
"com.linkedin.pegasus2avro.dataset.DatasetProperties": {
"customProperties": {
"model_maturity": "in dev",
"owner": "@alice",
"some_other_property": "test 1",
"node_type": "source",
"dbt_file_path": "models/base.yml",
"catalog_type": "BASE TABLE"
Expand Down Expand Up @@ -1083,6 +1086,9 @@
{
"com.linkedin.pegasus2avro.dataset.DatasetProperties": {
"customProperties": {
"model_maturity": "in prod",
"owner": "@bob",
"some_other_property": "test 2",
"node_type": "source",
"dbt_file_path": "models/base.yml",
"catalog_type": "BASE TABLE"
Expand Down Expand Up @@ -1545,6 +1551,9 @@
{
"com.linkedin.pegasus2avro.dataset.DatasetProperties": {
"customProperties": {
"model_maturity": "in prod",
"owner": "@charles",
"some_other_property": "test 3",
"node_type": "source",
"dbt_file_path": "models/base.yml",
"catalog_type": "BASE TABLE"
Expand Down