Skip to content

Commit

Permalink
add measure filters
Browse files Browse the repository at this point in the history
  • Loading branch information
owlas committed Apr 19, 2021
1 parent ab17fd9 commit b9e7999
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions dbt2looker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dbt2looker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LookerAggregateMeasures(str, Enum):
class Dbt2LookerMeasure(BaseModel):
name: str
type: LookerAggregateMeasures
filters: Optional[List[Dict[str, str]]] = []


class Dbt2LookerMeta(BaseModel):
Expand Down
3 changes: 3 additions & 0 deletions example/lookml/views/events.view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
view: events {
sql_table_name: alpine-land-278512.dbt.events ;;
}
11 changes: 10 additions & 1 deletion example/lookml/views/pages.view
Original file line number Diff line number Diff line change
Expand Up @@ -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%",
]
}
}
6 changes: 5 additions & 1 deletion example/models/prod/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9e7999

Please sign in to comment.