Skip to content

Commit

Permalink
Update code in lesson 5 and 6
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Jul 19, 2024
1 parent 450161a commit 68dbc27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ Open the `assets/dbt.py` file and do the following:
At this point, your `dbt.py` file should match the following:

```python
import os
from pathlib import Path

from dagster import AssetExecutionContext, AssetKey
from dagster_dbt import DagsterDbtTranslator, DbtCliResource, DbtProject, dbt_assets

from .constants import DBT_DIRECTORY
dbt_project = DbtProject(
project_dir=Path(__file__).joinpath("..", "..", "..", "analytics").resolve(),
)
dbt_project.prepare_if_dev()


class CustomizedDagsterDbtTranslator(DagsterDbtTranslator):
Expand All @@ -121,13 +125,10 @@ class CustomizedDagsterDbtTranslator(DagsterDbtTranslator):
else:
return super().get_asset_key(dbt_resource_props)


dbt_project = DbtProject(project_dir=DBT_DIRECTORY)
dbt_project.prepare_if_dev()



@dbt_assets(
manifest=dbt_project.manifest_path, dagster_dbt_translator=CustomizedDagsterDbtTranslator()
manifest=dbt_project.manifest_path,
dagster_dbt_translator=CustomizedDagsterDbtTranslator(),
)
def dbt_analytics(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,21 @@ def dbt_analytics(context: AssetExecutionContext, dbt: DbtCliResource):
At this point, the `dagster_university/assets/dbt.py` file should look like this:

```python
import os
import json
from pathlib import Path

from dagster import AssetExecutionContext, AssetKey
from dagster_dbt import DagsterDbtTranslator, DbtCliResource, DbtProject, dbt_assets

from .constants import DBT_DIRECTORY
from ..partitions import daily_partition


INCREMENTAL_SELECTOR = "config.materialized:incremental"

dbt_project = DbtProject(
project_dir=Path(__file__).joinpath("..", "..", "..", "analytics").resolve(),
)
dbt_project.prepare_if_dev()


class CustomizedDagsterDbtTranslator(DagsterDbtTranslator):
def get_asset_key(self, dbt_resource_props):
Expand All @@ -143,10 +147,6 @@ class CustomizedDagsterDbtTranslator(DagsterDbtTranslator):
return super().get_asset_key(dbt_resource_props)


dbt_project = DbtProject(project_dir=DBT_DIRECTORY)
dbt_project.prepare_if_dev()


@dbt_assets(
manifest=dbt_project.manifest_path,
dagster_dbt_translator=CustomizedDagsterDbtTranslator(),
Expand Down

0 comments on commit 68dbc27

Please sign in to comment.