From 9b9fe1346e518af8026e919cffe7e775fa93a083 Mon Sep 17 00:00:00 2001 From: "Wei-Chun, Chang" Date: Tue, 21 Nov 2023 13:51:02 +1100 Subject: [PATCH] Support dbt 1.7 metric filter format Signed-off-by: Wei-Chun, Chang --- piperider_cli/dbtutil.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/piperider_cli/dbtutil.py b/piperider_cli/dbtutil.py index 1f3ac88c3..491773ea5 100644 --- a/piperider_cli/dbtutil.py +++ b/piperider_cli/dbtutil.py @@ -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) + else: + statistics.add_field_one('nosupport') + return None 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 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) + else: + statistics.add_field_one('nosupport') + return None 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 nodes = metric.get('depends_on').get('nodes', []) depends_on = nodes[0]