Skip to content

Commit 0dd93fb

Browse files
committed
Add support for ephemeral models
1 parent 2dadff3 commit 0dd93fb

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Recent and upcoming changes to dbt2looker
44

5+
## Unreleased
6+
### Added
7+
- support ephemeral models (#57)
8+
59
## 0.11.0
610
### Added
711
- support label and hidden fields (#49)

dbt2looker/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Union, Dict, List, Optional
2+
from typing import Any, Union, Dict, List, Optional
33
try:
44
from typing import Literal
55
except ImportError:
@@ -144,6 +144,7 @@ class DbtModelColumn(BaseModel):
144144
class DbtNode(BaseModel):
145145
unique_id: str
146146
resource_type: str
147+
config: Dict[str, Any]
147148

148149

149150
class Dbt2LookerExploreJoin(BaseModel):
@@ -224,4 +225,4 @@ def case_insensitive_column_names(cls, v: Dict[str, DbtCatalogNodeColumn]):
224225

225226

226227
class DbtCatalog(BaseModel):
227-
nodes: Dict[str, DbtCatalogNode]
228+
nodes: Dict[str, DbtCatalogNode]

dbt2looker/parser.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@ def tags_match(query_tag: str, model: models.DbtModel) -> bool:
3131

3232
def parse_models(raw_manifest: dict, tag=None) -> List[models.DbtModel]:
3333
manifest = models.DbtManifest(**raw_manifest)
34-
all_models: List[models.DbtModel] = [
34+
materialized_models: List[models.DbtModel] = [
3535
node
3636
for node in manifest.nodes.values()
37-
if node.resource_type == 'model'
37+
if node.resource_type == 'model' and node.config['materialized'] != 'ephemeral'
3838
]
3939

40+
if tag is None:
41+
selected_models = materialized_models
42+
else:
43+
selected_models = [model for model in materialized_models if tags_match(tag, model)]
44+
4045
# Empty model files have many missing parameters
41-
for model in all_models:
46+
for model in selected_models:
4247
if not hasattr(model, 'name'):
4348
logging.error('Cannot parse model with id: "%s" - is the model file empty?', model.unique_id)
4449
raise SystemExit('Failed')
4550

46-
if tag is None:
47-
return all_models
48-
return [model for model in all_models if tags_match(tag, model)]
51+
return selected_models
4952

5053

5154
def check_models_for_missing_column_types(dbt_typed_models: List[models.DbtModel]):

0 commit comments

Comments
 (0)