Skip to content

Commit

Permalink
Support dbt 1.7 metric filter format
Browse files Browse the repository at this point in the history
Signed-off-by: Wei-Chun, Chang <wcchang@infuseai.io>
  • Loading branch information
wcchang1115 committed Nov 21, 2023
1 parent ad3ce42 commit 9b9fe13
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions piperider_cli/dbtutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,20 +468,39 @@ def _create_metric(name, filter=None, alias=None, root_name=None):
primary_entity = None
metric_filter = []
if metric.get('filter') is not None:
f = get_metric_filter(root_name, metric.get('filter'))
if f is not None:
metric_filter.append(f)
# in dbt 1.7, there's an additional layer of 'where_filters'
if 'where_filters' in metric.get('filter'):
for where_filter in metric.get('filter').get('where_filters', []):
f = get_metric_filter(root_name, where_filter)
if f is not None:
metric_filter.append(f)

Check warning on line 476 in piperider_cli/dbtutil.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/dbtutil.py#L473-L476

Added lines #L473 - L476 were not covered by tests
else:
statistics.add_field_one('nosupport')
return None

Check warning on line 479 in piperider_cli/dbtutil.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/dbtutil.py#L478-L479

Added lines #L478 - L479 were not covered by tests
else:
statistics.add_field_one('nosupport')
return None
f = get_metric_filter(root_name, metric.get('filter'))
if f is not None:
metric_filter.append(f)
else:
statistics.add_field_one('nosupport')
return None

Check warning on line 486 in piperider_cli/dbtutil.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/dbtutil.py#L485-L486

Added lines #L485 - L486 were not covered by tests

if filter is not None:
f = get_metric_filter(root_name, filter)
if f is not None:
metric_filter.append(f)
if 'where_filters' in filter:
for where_filter in filter.get('where_filters', []):
f = get_metric_filter(root_name, where_filter)
if f is not None:
metric_filter.append(f)

Check warning on line 493 in piperider_cli/dbtutil.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/dbtutil.py#L490-L493

Added lines #L490 - L493 were not covered by tests
else:
statistics.add_field_one('nosupport')
return None

Check warning on line 496 in piperider_cli/dbtutil.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/dbtutil.py#L495-L496

Added lines #L495 - L496 were not covered by tests
else:
statistics.add_field_one('nosupport')
return None
f = get_metric_filter(root_name, filter)
if f is not None:
metric_filter.append(f)
else:
statistics.add_field_one('nosupport')
return None

Check warning on line 503 in piperider_cli/dbtutil.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/dbtutil.py#L502-L503

Added lines #L502 - L503 were not covered by tests

nodes = metric.get('depends_on').get('nodes', [])
depends_on = nodes[0]
Expand Down

0 comments on commit 9b9fe13

Please sign in to comment.