From b9e799969aad2930efd1bbc3d01b5a2a77db9d60 Mon Sep 17 00:00:00 2001 From: oliverlaslett Date: Mon, 19 Apr 2021 14:14:29 +0100 Subject: [PATCH] add measure filters --- dbt2looker/generator.py | 1 + dbt2looker/models.py | 1 + example/lookml/views/events.view | 3 +++ example/lookml/views/pages.view | 11 ++++++++++- example/models/prod/pages.yml | 6 +++++- 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 example/lookml/views/events.view diff --git a/dbt2looker/generator.py b/dbt2looker/generator.py index fcd4c1c..a3edd98 100644 --- a/dbt2looker/generator.py +++ b/dbt2looker/generator.py @@ -171,6 +171,7 @@ def lookml_measures_from_model(model: models.DbtModel): 'type': measure.type.value, 'sql': f'${{TABLE}}.{column.name}', 'description': f'{measure.type.value.capitalize()} of {column.description}', + **({'filters': measure.filters} if measure.filters else {}) } for column in model.columns.values() for measure in column.meta.looker.measures diff --git a/dbt2looker/models.py b/dbt2looker/models.py index 7a8a72e..b6020ac 100644 --- a/dbt2looker/models.py +++ b/dbt2looker/models.py @@ -35,6 +35,7 @@ class LookerAggregateMeasures(str, Enum): class Dbt2LookerMeasure(BaseModel): name: str type: LookerAggregateMeasures + filters: Optional[List[Dict[str, str]]] = [] class Dbt2LookerMeta(BaseModel): diff --git a/example/lookml/views/events.view b/example/lookml/views/events.view new file mode 100644 index 0000000..5ed8899 --- /dev/null +++ b/example/lookml/views/events.view @@ -0,0 +1,3 @@ +view: events { + sql_table_name: alpine-land-278512.dbt.events ;; +} \ No newline at end of file diff --git a/example/lookml/views/pages.view b/example/lookml/views/pages.view index a0f5ed5..9a01b46 100644 --- a/example/lookml/views/pages.view +++ b/example/lookml/views/pages.view @@ -51,9 +51,18 @@ view: pages { description: "Website domain of the referrer. e.g. google.com" } - measure: Page views { + measure: Total page views { type: count sql: ${TABLE}.id ;; description: "Count of The primary key for this table" } + + measure: Blog views { + type: count + sql: ${TABLE}.id ;; + description: "Count of The primary key for this table" + filters: [ + path: "/blog%", + ] + } } \ No newline at end of file diff --git a/example/models/prod/pages.yml b/example/models/prod/pages.yml index 1232640..586b46c 100644 --- a/example/models/prod/pages.yml +++ b/example/models/prod/pages.yml @@ -10,8 +10,12 @@ models: meta: looker.com: measures: - - name: Page views + - name: Total page views type: count + - name: Blog views + type: count + filters: + - path: "/blog%" tests: - unique - not_null