Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ephemeral models #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Recent and upcoming changes to dbt2looker

## Unreleased
### Added
- support ephemeral models (#57)

## 0.11.0
### Added
- support label and hidden fields (#49)
Expand Down
5 changes: 3 additions & 2 deletions dbt2looker/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Union, Dict, List, Optional
from typing import Any, Union, Dict, List, Optional
try:
from typing import Literal
except ImportError:
Expand Down Expand Up @@ -144,6 +144,7 @@ class DbtModelColumn(BaseModel):
class DbtNode(BaseModel):
unique_id: str
resource_type: str
config: Dict[str, Any]


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


class DbtCatalog(BaseModel):
nodes: Dict[str, DbtCatalogNode]
nodes: Dict[str, DbtCatalogNode]
10 changes: 5 additions & 5 deletions dbt2looker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ def tags_match(query_tag: str, model: models.DbtModel) -> bool:

def parse_models(raw_manifest: dict, tag=None) -> List[models.DbtModel]:
manifest = models.DbtManifest(**raw_manifest)
all_models: List[models.DbtModel] = [
materialized_models: List[models.DbtModel] = [
node
for node in manifest.nodes.values()
if node.resource_type == 'model'
if node.resource_type == 'model' and node.config['materialized'] != 'ephemeral'
PaddyAlton marked this conversation as resolved.
Show resolved Hide resolved
]

# Empty model files have many missing parameters
for model in all_models:
for model in materialized_models:
if not hasattr(model, 'name'):
logging.error('Cannot parse model with id: "%s" - is the model file empty?', model.unique_id)
raise SystemExit('Failed')

if tag is None:
return all_models
return [model for model in all_models if tags_match(tag, model)]
return materialized_models
return [model for model in materialized_models if tags_match(tag, model)]


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